
我用JFrame做了一个类似QQ消息提示的窗口,但是任务栏中一直有一个图标显示着,怎么能将这个图标隐藏掉只剩一个窗口呢?
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import java.awt.Insets;
import java.awt.Toolkit;
import javax.swing.JDialog;
public class VersionUtil{
private Map<String, String> feaMap = null;
private Point oldP;//上一次坐标,拖动窗口时用
private TipWindow tw = null;//提示框
private ImageIcon img = null;//图像组件
private JLabel imgLabel = null; //背景图片标签
private JPanel headPan = null;
private JPanel feaPan =null;
private JPanel btnPan = null;
private JLabel title = null;
private JLabel head = null;
private JLabel close = null;//关闭按钮
private JTextArea feature = null;
private JScrollPane jfeaPan = null;
private JLabel releaseLabel = null;
private JLabel sure = null;
private SimpleDateFormat sdf=null;
{
sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
feaMap = new HashMap<String, String>();
feaMap.put("name", "中国信息大学固定资产管理系统");
feaMap.put("release", sdf.format(new Date()));
feaMap.put("feature", "1.开发环境:windows\n2.开发语言:java\n3.开发工具:Eclipse3.2\n4.数据库类型:SQL Server2005\n5.开发人员:花新昌\n6.联系方式:15210477080");
}
public VersionUtil() {
init();
handle();
tw.setAlwaysOnTop(true);
tw.setUndecorated(true);
tw.setResizable(false);
tw.setVisible(true);
tw.run();
}
public void init(){
//新建300x220的消息提示框
tw = new TipWindow(300, 220);
img = new ImageIcon("background.gif");
imgLabel = new JLabel(img);
//设置各个面板的布局以及面板中控件的边界
headPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
feaPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
btnPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
title = new JLabel("欢迎使用本系统");
head = new JLabel(feaMap.get("name"));
close = new JLabel(" x");//关闭按钮
feature = new JTextArea(feaMap.get("feature"));
jfeaPan = new JScrollPane(feature);
releaseLabel = new JLabel("登录 " + feaMap.get("release"));
sure = new JLabel("确定");
sure.setHorizontalAlignment(SwingConstants.CENTER);
// 将各个面板设置为透明,否则看不到背景图片
((JPanel) tw.getContentPane()).setOpaque(false);
headPan.setOpaque(false);
feaPan.setOpaque(false);
btnPan.setOpaque(false);
//设置JDialog的整个背景图片
tw.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
headPan.setPreferredSize(new Dimension(300, 60));
//设置提示框的边框,宽度和颜色
tw.getRootPane().setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.gray));
title.setPreferredSize(new Dimension(260, 26));
title.setVerticalTextPosition(JLabel.CENTER);
title.setHorizontalTextPosition(JLabel.CENTER);
title.setFont(new Font("宋体", Font.PLAIN, 12));
title.setForeground(Color.black);
close.setFont(new Font("Arial", Font.BOLD, 15));
close.setPreferredSize(new Dimension(20, 20));
close.setVerticalTextPosition(JLabel.CENTER);
close.setHorizontalTextPosition(JLabel.CENTER);
close.setCursor(new Cursor(12));
close.setToolTipText("关闭");
head.setPreferredSize(new Dimension(250, 35));
head.setVerticalTextPosition(JLabel.CENTER);
head.setHorizontalTextPosition(JLabel.CENTER);
head.setFont(new Font("宋体", Font.PLAIN, 12));
head.setForeground(Color.blue);
feature.setEditable(false);
feature.setForeground(Color.red);
feature.setFont(new Font("宋体", Font.PLAIN, 13));
feature.setBackground(new Color(184, 230, 172));
//设置文本域自动换行
feature.setLineWrap(true);
jfeaPan.setPreferredSize(new Dimension(250, 80));
jfeaPan.setBorder(null);
jfeaPan.setBackground(Color.black);
releaseLabel.setForeground(Color.DARK_GRAY);
releaseLabel.setFont(new Font("宋体", Font.PLAIN, 12));
//为了隐藏文本域,加个空的JLabel将他挤到下面去
JLabel jsp = new JLabel();
jsp.setPreferredSize(new Dimension(300, 25));
sure.setPreferredSize(new Dimension(110, 30));
//设置标签鼠标手形
sure.setCursor(new Cursor(12));
headPan.add(title);
headPan.add(close);
headPan.add(head);
feaPan.add(jsp);
feaPan.add(jfeaPan);
feaPan.add(releaseLabel);
btnPan.add(sure);
tw.add(headPan, BorderLayout.NORTH);
tw.add(feaPan, BorderLayout.CENTER);
tw.add(btnPan, BorderLayout.SOUTH);
}
public void handle() {
//为更新按钮增加相应的事件
sure.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
JOptionPane.showMessageDialog(tw, "谢谢,再见");
tw.close();
}
public void mouseEntered(MouseEvent e) {
sure.setBorder(BorderFactory.createLineBorder(Color.gray));
}
public void mouseExited(MouseEvent e) {
sure.setBorder(null);
}
});
//增加鼠标拖动事件
title.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
Point newP = new Point(e.getXOnScreen(), e.getYOnScreen());
int x = tw.getX() + (newP.x - oldP.x);
int y = tw.getY() + (newP.y - oldP.y);
tw.setLocation(x, y);
oldP=newP;
}
});
//鼠标按下时初始坐标,供拖动时计算用
title.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
oldP = new Point(e.getXOnScreen(), e.getYOnScreen());
}
});
//右上角关闭按钮事件
close.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
tw.close();
}
public void mouseEntered(MouseEvent e) {
close.setBorder(BorderFactory.createLineBorder(Color.gray));
}
public void mouseExited(MouseEvent e) {
close.setBorder(null);
}
});
}
public static void main(String args[]) {
new VersionUtil();
}
}
class TipWindow extends JDialog{
private static final long serialVersionUID = 8541659783234673950L;
private static Dimension dim;
private int x, y;
private int width, height;
private static Insets screenInsets;
public TipWindow(int width,int height){
this.width=width;
this.height=height;
dim = Toolkit.getDefaultToolkit().getScreenSize();
screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(this.getGraphicsConfiguration());
x = (int) (dim.getWidth() - width-3);
y = (int) (dim.getHeight()-screenInsets.bottom-3);
initComponents();
}
public void run() {
for (int i = 0; i <= height; i += 10) {
try {
this.setLocation(x, y - i);
Thread.sleep(5);
} catch (InterruptedException ex) {
}
}
//此处代码用来实现让消息提示框5秒后自动消失
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
close();
}
private void initComponents() {
this.setSize(width, height);
this.setLocation(x, y);
this.setBackground(Color.black);
}
public void close(){
x=this.getX();
y=this.getY();
int ybottom=(int)dim.getHeight()-screenInsets.bottom;
for (int i = 0; i <= ybottom-y; i += 10) {
try {
setLocation(x, y+i);
Thread.sleep(5);
} catch (InterruptedException ex) {
}
}
dispose();
}
}
目前在做一个qq那样的聊天软件,主程序打开后任务栏里会有程序图标的,不想要,怎么去掉呢? 找了好多资料,最后终于找到办法,不过前提是使用...//隐藏任务栏图标 只需要在new出Jframe对象后加上这条代码就可以了。
在任务栏上添加图标和事件,
java Swing最小化到任务栏图标,单击显示
无聊问题,嘿嘿嘿
解决办法: 打开任务文件夹,在地址栏输入,执行以下命令即可: cmd.exe /c ie4uinit.exe -show
publicstaticfinalImageFRAME_ABOUT=createImage("images/ABOUT.jpg"); protectedstaticImagecreateImage(Stringpath){ try{ Imageimage=...
创建文件,修改后缀为.bat 将下面代码复制进去 ... taskkill /f /im explorer.exe attrib -h -i %userprofile%\AppData\Local\IconCache.db del %userprofile%\AppData\Local\IconCache.db /a start explorer
electron 菜单栏If you are new here, please consider checking out my recent articles on Electron JS including Tray Icons. 如果您是新来的,请考虑查看我最近关于Electron JS的文章, 包括托盘图标 。 In ...
1、写回调函数: static BOOL CALLBACK StaticEnumWindowsProc(HWND hwnd, LPARAM lParam) { GetWindowText(hwnd, app_name, sizeof(app_name));... HICON hIcon = (HICON)GetClassLong(hwnd, GCL_...
该代码实现了在系统右下角的任务栏中显示程序的图标,并且最小化程序后单击图标可以显示出来这个程序窗口 import java.awt.Color; import java.awt.Image; import java.awt.MenuItem; import java....
怎么把长方形的任务栏图标改成正方形的那种不占空间的图标,就是没有文字只有一个正方形的图标的这种 怎么把长方形的任务栏图标改成正方形的这种不占空间的图标 ![图片说明]...
环境: jdk 1.4.2 win7 setIconImage(null)只会改变标题栏的图标。 注意:是任务栏,不是系统托盘图标,我想做类似qq来消息的闪烁效果。 搜了半天没搜到,请赐教。
Java 编程 登录界面 实现任务栏显示图标,关闭时隐藏
觉得锁定在任务栏的图片看起来不是很和谐。 替换图标的方法: 1.在eclipse安装包里搜索 javaee 然后对文件选中 选择打开文件位置。 2.然后替换 图中 javaee-ide_x32 、javaee-ide_x48 图片。javaee-ide_x32 、...
窗体设置默认的关闭操作,在很多软件中为避免关闭按钮退出程序,会设定关闭最小化托盘的操作,...另外,自定义的窗体图标导出为jar可执行文件后,常常不显示,解决办法是将图片资源放在src目录下,可自动打包进jar包。
第一种情况:图标没了,但任务量还在桌面图标电脑图解1右键点击桌面的空白处点击“查看”之后点击“显示桌面图标”电脑电脑图解2这样电脑的桌面图表就回来了电脑桌面图标电脑图解3第二种情况:开机所有的图标...
mac 菜单栏图标删除Your Mac’smenu bar can start to look a lot like the Windows system trayafter you install a few programs. Here’s how to declutter the menu bar and get those icons under control. ...
用Java写Mac APP时将JMenuBar显示到MacOS的菜单栏上并自定义菜单栏上程序的标题代码: 代码: import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class...
jf.setUndecorated(true); // 去掉窗口的装饰 jf.getRootPane().setWindowDecorationStyle(JRootPane.NONE); jf.addWindowStateListener(new WindowStateListener() { @Override publ
当单击任务栏时触发的消息是: WM_ACTIVE消息,其中wParam参数会指定何... 如果点击任务栏上的对话框最小化图标按钮,触发的是 WA_ACTIVE 消息,且 pWndOther 为NULL. void CMyDialog::OnActivate(UINT nStat...
思路:JFrame类中的setIconImage()方法 获取Image对象的实例方法 方法一:ImageIcon类的getImage()方法 ImageIcon icon = new ImageIcon(图片路径); setIconImage(icon.getImage()); 方法二:Toolkit类的getImage()...
SWT的系统托盘实现
5、任务栏图标设置 我们可以使用TrayIcon类来表示一个任务栏的图标 SystemTray tray = SystemTray.getSystemTray(); this.trayIcon = new TrayIcon(trayIconImage, "多线程下载工具", this.popupMenu); ...
此时窗口不是跳出来处于激活状态,而是在任务栏中高亮闪烁显示,类似QQ中聊天窗口的接收到消息时的效果。 这里是采用变通的方法,在JFrame窗体显示之后,JFrame不是当前的聚焦窗体,这时再次使用frame.setVisible...
deepin dde-dock 任务栏消失问题 在使用了任务栏的一些插件后,如果卸载的话,可能会把dde-dock的一些依赖也卸载掉,所以会导致dock栏出现问题,在查看了很多帖子后无果,也重新安装了几次还是不行,解决方案: 删除 ~/....
现提供两种方法: 方法一: 如果你用过Toolkit类,这将是一件很简单的事情: Toolkit tk=Toolkit.getDefaultToolkit() Image image=tk.createImage
刚使用win7的人可能会发现,自己打开的程序最小化到任务栏之后发现没有在任务栏显示,而是... 假如在系统桌面底部的任务栏上没找到正在运行的程序图标,点击任务栏右端的三角小按钮,就能看到隐藏的软件图标,如果里
产生原因 网传是因为接入外部扩展屏而扩展屏突然断开,从而导致IDEA窗口大小被更改,小到找不着 但是我发现我产生这个问题的原因不太一样,具体原因不详,且不可重现。 虽然我接了扩展屏,但是我的扩展屏没有断开,我...
如何在任务栏显示java程序图标2009-10-28 20:58:33 来源:WEB开发网核心提示:该代码实现了在系统右下角的任务栏中显示程序的图标,并且最小化程序后单击图标可以显示出来这个程序窗口,如何在任务栏显示java程序...
Python实现自动化办公视频教程:Excel处理、PDF转换、Word和PPT自动生成、Web自动处理。