자바 시스템 트레이 만들기

Creating Java System Tray

Posted by dydtjr1128 on May 25, 2017 · 170 words/1 min read Java

JAVA system tray

public void makeTray() {
    MenuItem exititem = new MenuItem("exit");
    PopupMenu menu = new PopupMenu("My Menu");

    menu.add(exititem);
    exititem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(1);
        }
    });

    TrayIcon myTray = 
        new TrayIcon(Toolkit.getDefaultToolkit().getImage(trayURL), "chat", menu);
    SystemTray tray = SystemTray.getSystemTray();

    try {
        tray.add(myTray);
    } catch (AWTException e1) {
        System.out.println(e1.getMessage());
    }
    myTray.setImageAutoSize(true);
}