英文:
Run Application in tray icon(not in taskbar)
问题
我想将我的应用程序在托盘中运行,但是我不想在任务栏中看到图标。
我在使用 Hide_On_Close 操作时使用了我的 JFrame。
我还在使用托盘图标来进行通知,但是在我的 GUI 应用程序运行时如何摆脱任务栏中的图标。
英文:
I want to run my app in the tray but I don't the icon in the taskbar.
I using my JFrame in Hide_On_Close operation
and I using a tray icon for notifications but how to get rid of the icon on the taskbar while my GUI application running.
答案1
得分: 1
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);
}
}
英文:
Does this work for you? You might need to add what os you're working on.
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);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论