让 Linux 中的 java 系统托盘看起来更漂亮
我正在 Linux 上制作一个使用 sytray 使用 Java 6 和 Swing 的 Java 应用程序。该应用程序看起来很棒(使用系统的外观和感觉),但系统托盘看起来很糟糕。我的意思是系统托盘菜单看起来像旧的小部件(Motif?)。我想知道是否有办法设置外观和感觉或使系统托盘更漂亮。
这是托盘的屏幕截图:
I'm making a Java Application on Linux that uses sytray using Java 6 and Swing. The app looks great (uses the system look and feel) but the systray looks awful. I mean the systray menu looks like old widgedts (Motif?). I wonder if there is a way to set a look and feel or something to make the system tray prettier.
Heres a screenshot of the tray:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您是否尝试过JXTrayIcon?
我在 Ubuntu 10.10 上使用 Compiz 从 SwingHelper 测试了这个演示,它看起来很酷。
更新
到 2020 年,这些链接已损坏,并且该解决方案目前存在许多缺点。例如,GNOME3 桌面环境已经完全删除了系统托盘图标,并用 AppIndicator 取代了它。
Java (AWT/Swing) 系统托盘支持今天已损坏。我建议使用这个 Java 库: https://github.com/dorkbox/SystemTray
从网站:
作为参考,您可以在 这里
Have you tried JXTrayIcon?
I tested this demo from SwingHelper on Ubuntu 10.10 with Compiz and it looks cool.
UPDATE
As 2020, these links are broken and this solution has many drawbacks today. For instance, GNOME3 desktop environments had removed entirely system tray icons and they replaced it with AppIndicator.
Java's (AWT/Swing) System Tray support is broken today. I recommend using this Java library: https://github.com/dorkbox/SystemTray
From the site:
For reference, you can found a copy of the original example at here
Swing 使用模拟的 UI 小部件。它有多种可供您应用的样式或主题。如果您希望获得更多本机结果,则需要寻找另一个小部件工具包。您有几个选择:
如果您的需求非常基本,您可能会对 AWT 感到满意,它是原始的 Java UI 工具包。它使用本机小部件,但支持的小部件库非常有限。
如果您想超越 AWT,请考虑 SWT,它由 eclipse.org 维护。它为您提供了丰富的小部件库,这些小部件是本机实现的。
Swing uses emulated UI widgets. It has a number of styles or themes you can apply. If you would prefer more native results you will need to look for another widget toolkit. You have a few options:
If your needs are very basic, you may be happy with AWT that is the original Java UI toolkit. It uses native widgets, but has very limited library of widgets that it supports.
If you want to go beyond AWT, consider SWT, which is maintained at eclipse.org. It gives you a rich library of widgets, that are implemented natively.
因为 Swing 在 Systray 上使用 AWT,如果您想要在系统托盘上看起来漂亮。也许你可以尝试使用 SWT :)
Because Swing use AWT on Systray, if you want great looking on systray. Maybe you can try with SWT :)
我为它编写了自己的库。这是链接:
http://www.2shared.com/file/sQdjb6aG/jtray。用法
:
该库使用了一些肮脏的技巧,因此它可能无法像在 Ubuntu 中那样在任何 Linux 平台上工作。它也应该适用于 Windows 和 OSX。
I wrote my own library for it. Here is the link:
http://www.2shared.com/file/sQdjb6aG/jtray.html
Usage:
The library uses a few dirty tricks, so maybe it may not work on any Linux platform as good as in Ubuntu. It should work for Windows and OSX as well.
我自己还没有尝试过,但是如果您使用的是 Java 6 Update 10 或更高版本,您可以使用新的 Nimbus 外观吗?:
使用 Nimbus LAF
我听说过 Ubuntu 上使用“JPopupMenu”的托盘图标,它使用 Nimbus 的外观和感觉,所以这可能是你最好的选择:
在 TrayIcon 中使用 JPopupMenu
据我所知,单独使用 JPopupMenu 将是一个很大的改进 - 与 Nimbus 结合使用应该很棒。
I haven't tried it myself, but if you're using Java 6 Update 10 or later, can you use the new Nimbus look and feel?:
Using Nimbus LAF
I've heard of tray icons using "JPopupMenu" on Ubuntu, which uses the Nimbus look and feel, so this may be your best bet:
Using JPopupMenu in TrayIcon
From what I've seen, using JPopupMenu alone would be a big improvement - coupled with Nimbus it should be awesome.
快速&肮脏的解决方法:
创建一个未修饰的 JDialog,为其添加一个 JPopupMenu,并根据需要使其从 TrayIcon 的鼠标侦听器中可见。
A quick & dirty workaround:
Create an undecorated JDialog, add a JPopupMenu for it and make it visible from your mouse listener of your TrayIcon as you want.