我使用 AWT Frames 创建了一个计算器。我想知道如何向我的 Cal 中添加托盘图标。我只能使用 AWT,不能使用 Swing。
最佳答案
final TrayIcon trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().createImage("pathToImage"));
final SystemTray tray = SystemTray.getSystemTray();
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
}
在此页面找到http://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html
在使用以下代码段之前,您还应该检查是否支持 SystemTray
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
//..
}
请注意,SystemTray
根据您的请求来自包 java.awt
。
关于java - 如何仅使用 AWT 设置系统托盘图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28241078/