
我用JFrame做了一个类似QQ消息提示的窗口,但是任务栏中一直有一个图标显示着,怎么能将这个图标隐藏掉只剩一个窗口呢?
final JWindow messagebox = new JWindow();
....
final ActionListener action = new ActionListener(){
public void actionPerformed(ActionEvent e){
messagebox.dispose();
}
};
final Timer timer = new Timer(TimeUnit.MINUTES.toMillis(3),action);
timer.setRepeat(false);
messagebox.addWindowListener(new WindowAdapter(){
public void windowOpened(WindowEvent e){
timer.start();
}
});
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();
}
}
java Swing最小化到任务栏图标,单击显示
目前在做一个qq那样的聊天软件,主程序打开后任务栏里会有程序图标的,不想要,怎么去掉呢? 找了好多资料,最后终于找到办法,不过前提是使用...//隐藏任务栏图标 只需要在new出Jframe对象后加上这条代码就可以了。
在任务栏上添加图标和事件,
publicstaticfinalImageFRAME_ABOUT=createImage("images/ABOUT.jpg"); protectedstaticImagecreateImage(Stringpath){ try{ Imageimage=...
Java 编程 登录界面 实现任务栏显示图标,关闭时隐藏
怎么把长方形的任务栏图标改成正方形的那种不占空间的图标,就是没有文字只有一个正方形的图标的这种 怎么把长方形的任务栏图标改成正方形的这种不占空间的图标 ![图片说明]...
electron 菜单栏If you are new here, please consider checking out my recent articles on Electron JS including Tray Icons. 如果您是新来的,请考虑查看我最近关于Electron JS的文章, 包括托盘图标 。 In ...
无聊问题,嘿嘿嘿
创建文件,修改后缀为.bat 将下面代码复制进去 ... taskkill /f /im explorer.exe attrib -h -i %userprofile%\AppData\Local\IconCache.db del %userprofile%\AppData\Local\IconCache.db /a start explorer
窗体设置默认的关闭操作,在很多软件中为避免关闭按钮退出程序,会设定关闭最小化托盘的操作,...另外,自定义的窗体图标导出为jar可执行文件后,常常不显示,解决办法是将图片资源放在src目录下,可自动打包进jar包。
该代码实现了在系统右下角的任务栏中显示程序的图标,并且最小化程序后单击图标可以显示出来这个程序窗口 import java.awt.Color; import java.awt.Image; import java.awt.MenuItem; import java.awt.PopupMenu; ...
浏览器有新消息之后,图标在电脑任务栏闪烁提示——看清楚是电脑任务栏,不是浏览器的tab标签的title文字,最近项目需求:浏览器有消息之后,如果用户离开,就在电脑任务...
一般情况下,点击程序任务栏的图标,程序会响应WM_SYSCOMMAND消息,然后再OnSysCommand()消息函数里面截取 (nID & 0xFFF0) == SC_MINIMIZE这个消息。 然后 ShowWindow(SW_HIDE); //隐藏当前窗口 ...
刚使用win7的人可能会发现,自己打开的程序最小化到任务栏之后发现没有在任务栏显示,而是... 假如在系统桌面底部的任务栏上没找到正在运行的程序图标,点击任务栏右端的三角小按钮,就能看到隐藏的软件图标,如果里
jf.setUndecorated(true); // 去掉窗口的装饰 jf.getRootPane().setWindowDecorationStyle(JRootPane.NONE); jf.addWindowStateListener(new WindowStateListener() { @Override publ
5、任务栏图标设置 我们可以使用TrayIcon类来表示一个任务栏的图标 SystemTray tray = SystemTray.getSystemTray(); this.trayIcon = new TrayIcon(trayIconImage, "多线程下载工具", this.popupMenu); ...
产生原因 网传是因为接入外部扩展屏而扩展屏突然断开,从而导致IDEA窗口大小被更改,小到找不着 但是我发现我产生这个问题的原因不太一样,具体原因不详,且不可重现。 虽然我接了扩展屏,但是我的扩展屏没有断开,我...
零零碎碎看了很多Qt例子,有一些很零散的窗体控制方法,在这总结一些。 1.更改窗体标题 this->setWindowTitle("窗体标题"); “窗体标题”就是更改的窗体标题 2.控制窗体大小 this->setMaximumSize(300,300);...
思路:JFrame类中的setIconImage()方法 获取Image对象的实例方法 方法一:ImageIcon类的getImage()方法 ImageIcon icon = new ImageIcon(图片路径); setIconImage(icon.getImage()); 方法二:Toolkit类的getImage()...
一、背景 最近有个需求,想把写好的bat脚本固定在任务栏上面,这样方便快速点击...现在怎么才能将这个kill java.bat文件固定在任务栏上面呢? 二、将bat批处理命令文件固定到任务栏 2.1 第一步,将kill java.bat ...
对于无标题栏窗体,也就是FormBorderStyle等于System.Windows.Forms.FormBorderStyle.None的窗体,点击任务栏图标的时候,是不能象标准窗体那样最小化或还原的。把下面的代码加到你的Form实现类中,即可实现点击任务...
把CHM帮助文档添加到任务栏 作为一名开发人员,难免会经常用到一些帮助文档,比如JDK的API帮助文档之类的.有时候为了方便需要将该文档固定到任务栏中方便随时查阅.由于帮助文档是不能直接固定到任务栏的,这也是写本文...
最小化代码: ...没错,点击任务栏图标,就只有这么一点,没有还原到之前的效果。 最后多次试验后发现,是由于我隐藏默认窗体的时候使用了另外一种风格,代码如下: primaryStage.initStyle(Stag...
import java.awt.Insets; import java.awt.Toolkit; import javax.swing.JFrame; public class TaskHeightTest extends JFrame{ private static final long serialVersionUID = 6587866382008362321L; pu...
看了一句很喜欢的话,想把它放在windows的任务栏上,象座右铭一样。在网上搜索了一下如何实现,发现都是修改时间的上下午符号来实现。如这儿所讲http://www.xitongcheng.com/jiaocheng/win10_article_17438.html ,...
第一种情况:图标没了,但任务量还在桌面图标电脑图解1右键点击桌面的空白处点击“查看”之后点击“显示桌面图标”电脑电脑图解2这样电脑的桌面图表就回来了电脑桌面图标电脑图解3第二种情况:开机所有的图标...
给Swing程序添加系统图标需要用到两个主要的类:SystemTray和TrayIcon。 SystemTray 通常用于判断系统是否支持托盘图标和添加系统图标功能;TrayIcon 用来创建一个图标,然后需要...import java.awt.AWTException;
* 设置窗口图标 */ protected void setWindowIcon() { ImageIcon imageIcon = new ImageIcon(getClass().getResource( "/cn/wuhongbox/j2se/myAppTest/res/image/icon.jpg")); ...
这段代码基本从 ... 然后稍稍改动了点地方, 并且加上了一些注释 [code="java"]import java.awt.AWTException;...import java.awt.Image;...import java.awt.MenuItem;...import java.awt.PopupMe...
例子主要包括SocketAsyncEventArgs通讯封装、服务端实现日志查看、SCOKET列表、上传、下载、远程文件流、吞吐量协议,用于测试SocketAsyncEventArgs的性能和压力,最大连接数支持65535个长连接,最高命令交互速度达到250MB/S(使用的是127.0.0.1的方式,相当于千兆网卡1Gb=125MB/S两倍的吞吐量)。服务端用C#编写,并使用log4net作为日志模块; 同时支持65536个连接,网络吞吐量可以达到400M。