Swing组件:竖排文本问题

发布于 2024-07-08 11:43:52 字数 431 浏览 6 评论 0原文

如果我有一个类似于此图片中的按钮:

http://www .freeimagehosting.net/image.php?4cd775814c.png

我怎样才能使文本垂直显示? 正如

j
B
u
t
t
o
n
1

我想知道如何为 JLabel 做同样的事情。 我确信必须有一种更好的方法,而不是创建与字符串中的字符一样多的标签。 正确的 ?

编辑:如何将图像插入到我的帖子中? 图像按钮在预览部分显示图像,但是当我实际发布数据时,我只得到一些文本,就像标签变得混乱一样。

If I have a button like the one in this image :

http://www.freeimagehosting.net/image.php?4cd775814c.png

how could I make the text display itself vertically ? As in

j
B
u
t
t
o
n
1

I would like to know how to do the same thing for JLabel . I'm sure there has to be a better way than to create as many labels as there are characters in the string . Right ?

EDIT: how can I insert an image into my post ? The button for the image shows the image in the preview section , but when I actually post the data , I only get some text back , like the tags are getting messed up .

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

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

发布评论

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

评论(2

棒棒糖 2024-07-15 11:43:52

我不知道这对您是否有用,但是此示例展示了如何制作垂直标签。 不同之处在于它旋转所有文本(和/或图标)而不是堆叠字母。 我不知道修改它来完成你所要求的事情会有多困难。

这样做的好处是你的标签可以在运行时更改; 与简单的 label.setUI(new VerticalLabelUI(true)); 相比,生成大的 HTML 字符串可能会很痛苦(而且您不必担心标签文本中的 <>)。

I don't know if this is useful to you, but this sample shows how to make a vertical label. The difference is that it rotates all of the text (and/or the icon) instead of stacking the letters. I don't know how difficult it would be to modify it to do what you're asking.

The advantage of doing it this way is if your labels can change at runtime; generating big HTML strings might be a pain compared to a simple label.setUI(new VerticalLabelUI(true)); (and you don't have to worry about <> in the label text).

零時差 2024-07-15 11:43:52

您可以将 HTML 用于 JButton 或 JLabel。 所以

button = new JButton("<html>J<br>b<br>u<br>t<br>t<br>o<br>n<br>1</html>");

应该这样做。

You can use HTML for JButton or JLabel. So

button = new JButton("<html>J<br>b<br>u<br>t<br>t<br>o<br>n<br>1</html>");

should do the trick.

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