2013-01-09 49 views

回答

0

妈妈快看,这里没有窗户,只有我们的泰迪熊......

enter image description here

public class TestTrayIcon01 { 

    public static void main(String[] args) { 
     new TestTrayIcon01(); 
    } 

    public TestTrayIcon01() { 
     EventQueue.invokeLater(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        TrayIcon icon = new TrayIcon(ImageIO.read(getClass().getResource("/SmallTeddy.png"))); 
        SystemTray tray = SystemTray.getSystemTray(); 
        tray.add(icon); 
       } catch (Exception ex) { 
        ex.printStackTrace(); 
       } 
       JDialog dialog = new JDialog(); 
       dialog.setSize(100, 100); 
       dialog.setVisible(true); 
      } 
     }); 
    } 

} 

JDialogJWindow(Windows下)将不会显示在任务栏上的 “图标”。我很确定,在Mac下它几乎是不可能的,不存在码头图标...

+0

的组合非常感谢许多。有什么办法可以让它在关闭时在后台运行? – user1910744

+0

何时关门? – MadProgrammer

+0

java.lang.NullPointerException。 :((并且当JFrame被关闭时) – user1910744