本文介绍了如何将Java应用程序放入系统托盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小控制面板,只是我做的一个小应用程序。我想最小化/放置控制面板与电子设备,电池寿命,日期,网络等。
I have a little control-panel, just a little application that I made. I would like to minimize/put the control-panel up/down with the systemicons, together with battery life, date, networks etc.
任何可以给我一个线索的人,链接到教程或要阅读的内容?
Anyone that can give me a clue, link to a tutorial or something to read?
推荐答案
从Java 6开始,和课程。 SystemTray
在其Javadocs中有一个非常广泛的例子:
As of Java 6, this is supported in the SystemTray
and TrayIcon
classes. SystemTray
has a pretty extensive example in its Javadocs:
TrayIcon trayIcon = null;
if (SystemTray.isSupported()) {
// get the SystemTray instance
SystemTray tray = SystemTray.getSystemTray();
// load an image
Image image = Toolkit.getDefaultToolkit().getImage("your_image/path_here.gif");
// create a action listener to listen for default action executed on the tray icon
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
// execute default action of the application
// ...
}
};
// create a popup menu
PopupMenu popup = new PopupMenu();
// create menu item for the default action
MenuItem defaultItem = new MenuItem(...);
defaultItem.addActionListener(listener);
popup.add(defaultItem);
/// ... add other items
// construct a TrayIcon
trayIcon = new TrayIcon(image, "Tray Demo", popup);
// set the TrayIcon properties
trayIcon.addActionListener(listener);
// ...
// add the tray image
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println(e);
}
// ...
} else {
// disable tray option in your application or
// perform other actions
...
}
// ...
// some time later
// the application state has changed - update the image
if (trayIcon != null) {
trayIcon.setImage(updatedImage);
}
// ...
您还可以查看,或。
这篇关于如何将Java应用程序放入系统托盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!