import java.awt.*;
public class TrayIconDemo {
public static void main(String[] args) throws AWTException, java.net.MalformedURLException {
if (SystemTray.isSupported()) {
TrayIconDemo td = new TrayIconDemo();
td.displayTray();
} else {
System.err.println("System tray not supported!");
}
}
public void displayTray() throws AWTException, java.net.MalformedURLException {
//Obtain only one instance of the SystemTray object
SystemTray tray = SystemTray.getSystemTray();
//If the icon is a file
Image image = Toolkit.getToolkit().createImage("icon.png");
//Alternative (if the icon is on the classpath):
//Image image = Toolkit.getToolkit().createImage(getClass().getResource("icon.png"));
TrayIcon trayIcon = new TrayIcon(image, "Tray Demo");
//Let the system resizes the image if needed
trayIcon.setImageAutoSize(true);
//Set tooltip text for the tray icon
trayIcon.setToolTip("System tray icon demo");
tray.add(trayIcon);
trayIcon.displayMessage("Hello, World", "notification demo", TrayIcon.MessageType.INFO);
}
}
当我将鼠标悬停在SystemTray或TrayIcon上时,我收到以下消息:
Usage of API documented as @since 1.6+ less... (Ctrl+F1)
This inspection finds all usages of methods that have @since tag in their documentation. This may be useful when development is performed under newer SDK version as the target platform for production.
这些课程带有红色下划线。我使用的是Windows 7 Enterprise,64位,SP1。可能是什么问题?
答案 0 :(得分:0)
您的代码没有什么问题,但是您在IDE中的项目配置有问题。
在问题的评论中,您已经写到您正在使用IntelliJ IDEA。在IntelliJ IDEA中,您可以通过以下方式检查设置:
希望有帮助。