把应用程序的窗体最小化时放到右下角的任务栏怎么做呀? 把应用程序的窗体最小化时放到右下角的任务栏怎么做呀?整了好长时间没找着,java里可以办到吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那个叫托盘区,不是任务栏了.你找托盘编程相关的东西就行了, swt提供了.其他一些jar也实现了. 你用jdk6就可以了啊,新加的功能。 恩下一个jdk1.6beta版就可以实现了,以前的不行 JDK1.6实现package mainform;import java.awt.SystemTray;import java.awt.*;import java.awt.Toolkit;import java.awt.event.*;import javax.swing.*;public class MainForm extends JFrame implements MouseListener{ TrayIcon trayIcon = null; Container c=null; public MainForm() { } /** * @param args */ public static void main(String[] args) { MainForm mainform=new MainForm(); mainform.init(); mainform.getInitFace(); //JFrame form=new JFrame(); mainform.setLocation(150,100); mainform.setSize(500,300); mainform.setBackground(new Color(125,125,125)); //form.setBounds(100,50,500,300); mainform.setVisible(true); mainform.setEnabled(true); mainform.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); } public void init() { if (SystemTray.isSupported()) { // get the SystemTray instance SystemTray tray = SystemTray.getSystemTray(); // load an image Image image =Toolkit.getDefaultToolkit().getImage("D:\\programs\\work\\test162\\src\\mainform\\jws-dukeonly.gif"); // create a action listener to listen for default action executed on the tray icon ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { if(e.getActionCommand()=="rightKey") { //MainForm.this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); System.exit(0); } } catch(Exception ex) { ex.printStackTrace(); } } }; // create a popup menu PopupMenu popup = new PopupMenu(); // create menu item for the default action MenuItem defaultItem = new MenuItem("Exit"); defaultItem.addActionListener(listener); defaultItem.setActionCommand("rightKey"); popup.add(defaultItem); /// ... add other items // construct a TrayIcon trayIcon = new TrayIcon(image, "Tray Demo", popup); // set the TrayIcon properties trayIcon.addActionListener(listener); trayIcon.addMouseListener(this); // ... // add the tray image try { tray.add(trayIcon); } catch (AWTException e) { System.err.println(e); } // ... c=this.getContentPane(); } else { // disable tray option in your application or // perform other actions //... } // ... // some time later // the application state has changed - update the image// if (trayIcon != null) // {// trayIcon.setImage(updatedImage);// } } public InitFace getInitFace() { return new InitFace(); } public class InitFace extends JPanel { public InitFace() { init(); } public void init() { c.add(this); } public void paintComponent(Graphics g) { Font font=new Font("Dialog",Font.BOLD,20); g.setFont(font); g.setColor(Color.RED); g.drawString("雪丽是我老婆!",150,150); } } public void actionPerformed(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseClicked(MouseEvent e) { //点击系统托盘图标和鼠标左键 if(e.getSource()==this.trayIcon && e.getButton()==e.BUTTON1 ) { if(e.getClickCount()==1)//单击 { this.setVisible(true); System.out.println("implemented1"); } else if(e.getClickCount()==2)//双击 { System.out.println("implemented2"); } } } public void mousePressed(MouseEvent e) { } }而JDK1.5及以前版本都必须使用JNI技术,用C或C++调用WINDOWS API java robot 和剪贴板交互问题 java回调的有关问题 Java 获取 网络传输速率 日期字符串,请大家帮忙!谢谢了, [12]这个正则表达式怎么写? 怎样写一个JAVA控制台应用程序,要求能够打开一个窗口并且能开始游戏? jTree怎样序列化? 一个关于GridLayout的怪问题 在window 下如何编译这种java文件! 怎么卸载JBuilder4?为什么找不到可以卸载它的程序? Java开发MapInfo程序 帮我一下 谢谢
其他一些jar也实现了.
package mainform;
import java.awt.SystemTray;
import java.awt.*;
import java.awt.Toolkit;
import java.awt.event.*;
import javax.swing.*;
public class MainForm extends JFrame implements MouseListener
{
TrayIcon trayIcon = null;
Container c=null;
public MainForm()
{
}
/**
* @param args
*/
public static void main(String[] args)
{
MainForm mainform=new MainForm();
mainform.init();
mainform.getInitFace();
//JFrame form=new JFrame();
mainform.setLocation(150,100);
mainform.setSize(500,300);
mainform.setBackground(new Color(125,125,125));
//form.setBounds(100,50,500,300);
mainform.setVisible(true);
mainform.setEnabled(true);
mainform.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public void init()
{
if (SystemTray.isSupported()) {
// get the SystemTray instance
SystemTray tray = SystemTray.getSystemTray();
// load an image
Image image =Toolkit.getDefaultToolkit().getImage("D:\\programs\\work\\test162\\src\\mainform\\jws-dukeonly.gif");
// create a action listener to listen for default action executed on the tray icon
ActionListener listener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
if(e.getActionCommand()=="rightKey")
{
//MainForm.this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
System.exit(0);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
};
// create a popup menu
PopupMenu popup = new PopupMenu();
// create menu item for the default action
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(listener);
defaultItem.setActionCommand("rightKey");
popup.add(defaultItem);
/// ... add other items
// construct a TrayIcon
trayIcon = new TrayIcon(image, "Tray Demo", popup);
// set the TrayIcon properties
trayIcon.addActionListener(listener);
trayIcon.addMouseListener(this);
// ...
// add the tray image
try
{
tray.add(trayIcon);
}
catch (AWTException e)
{
System.err.println(e);
}
// ...
c=this.getContentPane();
}
else
{
// disable tray option in your application or
// perform other actions
//...
}
// ...
// some time later
// the application state has changed - update the image
// if (trayIcon != null)
// {
// trayIcon.setImage(updatedImage);
// } }
public InitFace getInitFace()
{
return new InitFace();
}
public class InitFace extends JPanel
{
public InitFace()
{
init();
}
public void init()
{
c.add(this);
}
public void paintComponent(Graphics g)
{
Font font=new Font("Dialog",Font.BOLD,20);
g.setFont(font);
g.setColor(Color.RED);
g.drawString("雪丽是我老婆!",150,150);
}
}
public void actionPerformed(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
//点击系统托盘图标和鼠标左键
if(e.getSource()==this.trayIcon && e.getButton()==e.BUTTON1 )
{
if(e.getClickCount()==1)//单击
{
this.setVisible(true);
System.out.println("implemented1");
}
else if(e.getClickCount()==2)//双击
{
System.out.println("implemented2");
}
}
}
public void mousePressed(MouseEvent e)
{
}
}
而JDK1.5及以前版本都必须使用JNI技术,用C或C++调用WINDOWS API