【问题标题】:Simple way to add window to system tray [duplicate]将窗口添加到系统托盘的简单方法[重复]
【发布时间】:2013-01-13 04:02:47
【问题描述】:

可能重复:
How can I put my Java program in the system tray?

我正在用java制作一个通知系统,我希望程序显示在系统托盘中,而不是在任务栏上,我试过了:

notification.setExtendedState(JFrame.ICONIFIED);

这不仅不起作用,而且还落后于我的电脑 当前代码:

public static void notify(String line1, String line2, String imagepath, int style){
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int width = gd.getDisplayMode().getWidth();
        int swidth = width - 320;

        JFrame notification = new JFrame();
        JPanel main = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        main.setLayout( new GridLayout( 2 , 1 ) );



        JLabel notifyline1 = new JLabel();
        notifyline1.setText(line1);
        notifyline1.setFont(new Font("Minecraft",1 , 16));
        notifyline1.setForeground(new Color(242, 238, 17));
        main.add(notifyline1);

        JLabel notifyline2 = new JLabel();
        notifyline2.setText(line2);
        notifyline1.setFont(new Font("Minecraft",1 , 12));
        notifyline1.setForeground(Color.black);
        main.add(notifyline1);

        notification.add(main);
        notification.setExtendedState(JFrame.ICONIFIED);
        notification.setSize(new Dimension(320,64));
        notification.setLocation(swidth, 0);
        notification.setUndecorated(true);
        notification.setVisible(true);
    }

另外,用一块石头杀死 2 只鸟 有没有办法给jlabel上色,试过了

label1.setForegroundColor(new Color(100, 100, 100));

【问题讨论】:

    标签: java swing jframe system-tray


    【解决方案1】:

    Java 有TrayIcon 类,可用于将应用程序最小化为SystemTray。您可以查看工作示例here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-21
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 2011-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多