Java TrayIcon.displayMessage() 和换行符
我正在编写一个带有 SystemTray 图标的 Java 应用程序,我想在 TrayIcon 的“显示消息”中添加换行符,但普通的 html 技巧似乎不起作用(就像在 JLabels 中那样)。
在下面的示例中,trayIcon 变量的类型为“java.awt.TrayIcon”。
<代码> 托盘Icon.displayMessage("标题", "
Blah
\r\n Blahblah ...blah", TrayIcon.MessageType.INFO);
Java 忽略 \r\n,但显示 html 标签。
有什么想法吗?
如果没有,我会使用 JFrame 之类的。
更新:这似乎是一个特定于平台的问题,我应该在问题中指定我的操作系统:我需要它在 Windows 和 Linux 上工作。
Nishan 展示了 \n 在 Windows 上运行,我用我旁边的 Vista 盒子进行了确认。 看起来我需要用 JFrame 或消息框定制一些东西,
干杯
I'm writing a Java app with a SystemTray icon, and I'd like to put line-breaks into the TrayIcon's "display message", but the normal html trick doesn't seem to work (like it does inside JLabels).
In the example below, the trayIcon variable below is of type "java.awt.TrayIcon".
trayIcon.displayMessage("Title", "<p>Blah</p> \r\n Blah <br> blah ... blah", TrayIcon.MessageType.INFO);
Java ignores the \r\n, but displays the html tags.
Any ideas?
If not, I'll use a JFrame or something.
UPDATE: it seems to be a platform-specific issue, and I should have specified my OS in the question: I need this to work on Windows and Linux.
Nishan showed that a \n works on Windows, and I confirmed with a Vista box I now have next to me.
It looks like I'll need to make something custom with a JFrame or a messagebox
Cheers guys
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
附加 \n 对我有用:
Appending \n worked for me :
正如此处所述,无法在托盘图标消息中显示新行在Linux中。
刚才有一个对我有用的棘手想法。观察到消息中每行显示的字符数。对我来说,它每行显示 56 个字符。
因此,如果一行少于 56 个字符,请用空格填充空白,使其达到 56 个字符。
知道这不是正确的方法,但找不到其他替代方法。现在我的输出符合预期。
所以,我尝试了另一种方法
最后
As mentioned here, it is not possible to show new lines in tray icon messages in Linux.
Just now got a tricky idea which worked for me. Observed number of characters getting displayed per line in the message. For me it is showing 56 characters per line.
So, if a line has got less than 56 characters, fill the gap with spaces to make it 56 characters.
Knew this is not a proper way but could not find other alternatives. Now my output is as expected.
So, i tried another approach
And finally