[英]JFrame - Icon not showing on Sys tray when JFrame has been minimised
我目前正在设法将JFrame最小化到系统托盘,并且已成功完成,如下所示:
//
URL resource = panel.getClass().getClassLoader().getResource("boston.png");
System.out.println("rfc95Panel.getClass().getClassLoader().getResource() is: " + rfc95Panel.getClass().getClassLoader().getResource("boston.png"));
Image image = Toolkit.getDefaultToolkit().getImage(resource);
//
frame.setIconImage(image);
//
if (SystemTray.isSupported()) {
final TrayIcon icon = new TrayIcon(image);
icon.setToolTip("Program minimised");
//
icon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.setVisible(true);
frame.setExtendedState(frame.NORMAL);
getSystemTray().remove(icon);
}
});
// Adds the specified window state listener to receive window events
// from this window. If l is null, no exception is thrown and no action
// is performed.
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowIconified(WindowEvent e) {
frame.setVisible(false);
try {
getSystemTray().add(icon);
} catch (AWTException e1) {
e1.printStackTrace();
}
}
});
}
问题是最小化时,打开系统托盘时看不到图像/图标,即可以看到工具提示,但看不到与程序相关的图标-请参见下图
关于我所缺少的任何想法吗? 我觉得这可能是基本的东西。
我遇到的上述问题的简单答案是打算用作系统任务栏图标的图像大小。 基本上我的尺寸是64 x 64,但理想情况下应该是尺寸较小,在我的情况下,我将图像缩小到16 x 16。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.