让 Linux 中的 java 系统托盘看起来更漂亮

发布于 2024-10-14 06:15:49 字数 351 浏览 3 评论 0原文

我正在 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:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

可爱暴击 2024-10-21 06:15:49

您是否尝试过JXTrayIcon

我在 Ubuntu 10.10 上使用 Compiz 从 SwingHelper 测试了这个演示,它看起来很酷。

更新

到 2020 年,这些链接已损坏,并且该解决方案目前存在许多缺点。例如,GNOME3 桌面环境已经完全删除了系统托盘图标,并用 AppIndicator 取代了它。

Java (AWT/Swing) 系统托盘支持今天已损坏。我建议使用这个 Java 库: https://github.com/dorkbox/SystemTray

从网站:

对 Java 6+ 上的 Swing/AWT、GtkStatusIcon 和 AppIndicator 提供专业、跨平台的 SystemTray 支持。该库提供操作系统本机菜单和 Swing/AWT 菜单,具体取决于操作系统和桌面环境以及是否启用了自动检测(默认)。

作为参考,您可以在 这里

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:

Professional, cross-platform SystemTray support for Swing/AWT, GtkStatusIcon, and AppIndicator on Java 6+. This library provides OS Native menus and Swing/AWT menus, depending on the OS and Desktop Environment and if AutoDetect (the default) is enabled.

For reference, you can found a copy of the original example at here

风情万种。 2024-10-21 06:15:49

Swing 使用模拟的 UI 小部件。它有多种可供您应用的样式或主题。如果您希望获得更多本机结果,则需要寻找另一个小部件工具包。您有几个选择:

  1. 如果您的需求非常基本,您可能会对 AWT 感到满意,它是原始的 Java UI 工具包。它使用本机小部件,但支持的小部件库非常有限。

  2. 如果您想超越 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:

  1. 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.

  2. 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.

时间你老了 2024-10-21 06:15:49

因为 Swing 在 Systray 上使用 AWT,如果您想要在系统托盘上看起来漂亮。也许你可以尝试使用 SWT :)

Because Swing use AWT on Systray, if you want great looking on systray. Maybe you can try with SWT :)

翻身的咸鱼 2024-10-21 06:15:49

我为它编写了自己的库。这是链接:

http://www.2shared.com/file/sQdjb6aG/jtray。用法

import javax.swing.jtray.*;

JTrayIcon.initSystemTray();
JTrayIcon icon = new JTrayIcon(img, "Tooltip", jpopupmenu);
icon.displayMessage(null, "Title", "Multiline\nsecondline", 3000); // 3 seconds

该库使用了一些肮脏的技巧,因此它可能无法像在 Ubuntu 中那样在任何 Linux 平台上工作。它也应该适用于 Windows 和 OSX。

I wrote my own library for it. Here is the link:

http://www.2shared.com/file/sQdjb6aG/jtray.html

Usage:

import javax.swing.jtray.*;

JTrayIcon.initSystemTray();
JTrayIcon icon = new JTrayIcon(img, "Tooltip", jpopupmenu);
icon.displayMessage(null, "Title", "Multiline\nsecondline", 3000); // 3 seconds

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.

朦胧时间 2024-10-21 06:15:49

我自己还没有尝试过,但是如果您使用的是 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.

做个少女永远怀春 2024-10-21 06:15:49

快速&肮脏的解决方法:
创建一个未修饰的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文