【发布时间】:2010-09-24 18:56:24
【问题描述】:
我正在使用以下代码在 Windows 和 Linux 中设置托盘图标。它在 Windows 中运行良好,在 Linux 中运行良好。在 Linux(Ubuntu)中,我将面板设置为(有点)透明,当我添加 GIF(具有透明背景)时,图标的背景显示为灰色和丑陋(参见图像,绿色菱形“!”)。 ...关于如何使我添加的 GIF 图像“保持”其透明背景的任何想法?
alt text http://unarm.org/stackoverflow/panel_task.jpg
还有我正在使用的图片,如果你想测试的话:
alt text http://unarm.org/stackoverflow/green_info.gif
import java.awt.*;
import java.awt.event.*;
public class TrayFun {
static class ShowMessageListener implements ActionListener {
TrayIcon trayIcon;
String title;
String message;
TrayIcon.MessageType messageType;
ShowMessageListener(
TrayIcon trayIcon,
String title,
String message,
TrayIcon.MessageType messageType) {
this.trayIcon = trayIcon;
this.title = title;
this.message = message;
this.messageType = messageType;
}
public void actionPerformed(ActionEvent e) {
trayIcon.displayMessage(title, message, messageType);
}
}
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
if (SystemTray.isSupported()) {
final SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("green_info.png");
PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon = new TrayIcon(image, "The Tip Text", popup);
trayIcon.setImageAutoSize(true);
MenuItem item = new MenuItem("Close");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tray.remove(trayIcon);
}
});
popup.add(item);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("Can't add to tray");
}
} else {
System.err.println("Tray unavailable");
}
}
};
EventQueue.invokeLater(runner);
}
}
【问题讨论】:
-
我猜你必须切换到一个方形图标 :( :( 很高兴你发现 SystemTray 是你的守护程序应用程序的一个很好的替代品。这个新应用程序是关于什么的?: ) 这是秘密吗?
-
问题,这个图标图像在其他地方显示时是否看起来不透明?例如网页?
-
这是一个秘密,但我计划很快将它作为一个开源项目发布在这里。图像在其他任何地方显示时看起来都很好。你可以看到我已经嵌入了我的任务栏图像下方和代码上方。
标签: java linux panel gnome tray