簡體   English   中英

在托盤圖標中運行應用程序(不在任務欄中)

[英]Run Application in tray icon(not in taskbar)

我想在托盤中運行我的應用程序,但我沒有任務欄中的圖標。

我在 Hide_On_Close 操作中使用我的 JFrame

我使用托盤圖標作為通知,但如何在我的 GUI 應用程序運行時擺脫任務欄上的圖標。

這對你有用嗎? 您可能需要添加您正在使用的操作系統。

import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
public class SysTrayFrame{

    public static void main(String[] args) throws Exception{
        JFrame frame = new JFrame("systray test");
        frame.setUndecorated(true);
        BufferedImage img =  new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
        Graphics g = img.getGraphics();
        g.setColor(Color.RED);
        g.fillOval(0, 0, 64, 64);
        g.dispose();
        JButton b = new JButton("click to hide");
        frame.add(b);
        b.addActionListener(evt-> frame.setVisible(false) );
        frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
        TrayIcon icon = new TrayIcon(img);
        icon.addActionListener( evt->{
            System.out.println("doing it");
            frame.setVisible(true);
        });
        SystemTray.getSystemTray().add(icon);
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM