Java:如何使用AWT显示多行工具提示?

发布于 2024-09-03 00:27:28 字数 498 浏览 3 评论 0原文

我编写了一个应用程序,现在正在制作一个托盘图标。现在我想为托盘图标设置多行工具提示文本。但我不知道怎么办。我知道如何使用 Swing 执行此操作:

component.setToolTipText("<html>Line 1<br>Line2</html>");

但这不适用于 AWT。此外,通过 \n 分隔行也不起作用。

我在 Linux 上运行:

Ubuntu 10.04
Kernel Linux 2.6.32-22-generic
GNOME 2.30.0
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK Server VM (build 14.0-b16, mixed mode)

任何帮助将不胜感激。
谢谢

I wrote an application and now I'm making a tray-icon. Now I want to set a multi-line tooltiptext to the tray-icon. But I don't know how. I know how to do this with Swing:

component.setToolTipText("<html>Line 1<br>Line2</html>");

But this doesn't work with AWT. Also serarating lines by \n doesn't work.

I'm running on linux:

Ubuntu 10.04
Kernel Linux 2.6.32-22-generic
GNOME 2.30.0
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK Server VM (build 14.0-b16, mixed mode)

Any help would be very appreciated.
Thanks

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

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

发布评论

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

评论(2

淑女气质 2024-09-10 00:27:29

以下代码为我生成了一个完美的多行工具提示:

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class AWTScratch {
    public static void main(String[] args) {
        BufferedImage im = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);
        TrayIcon ti = new TrayIcon(im, "Multiline\nmulti");
        ti.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        ti.setImageAutoSize(true);
        if (SystemTray.isSupported()){
            SystemTray st=SystemTray.getSystemTray();
            try {
                st.add(ti);
            } catch (AWTException e1) {
                e1.printStackTrace();
            }
        }
    }
}

也许是平台问题。你能给我们你的操作系统和jvm版本吗?似乎是一个错误,请参阅 suns bug 数据库

The following code produced a perfectly fine multi line tooltip for me:

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class AWTScratch {
    public static void main(String[] args) {
        BufferedImage im = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);
        TrayIcon ti = new TrayIcon(im, "Multiline\nmulti");
        ti.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        ti.setImageAutoSize(true);
        if (SystemTray.isSupported()){
            SystemTray st=SystemTray.getSystemTray();
            try {
                st.add(ti);
            } catch (AWTException e1) {
                e1.printStackTrace();
            }
        }
    }
}

Maybe its a platform issue. Could you give us your OS and jvm version? Seems to be a bug, see inside suns bug database.

喜爱皱眉﹌ 2024-09-10 00:27:29

JToolTip 派生自 JComponent,但您可以使用仅 Graphics 的方法自己模拟效果,如 AlphaView 中所示> 此示例的类。

JToolTip derives from JComponent, but you can simulate the effect yourself using Graphics-only methods, as shown in the AlphaView class of this example.

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