使用标签使按钮文本带有下划线,导致按钮占据整个 JToolBar
我需要一个按钮,其文本带有下划线,而我在 Java 中找到的唯一方法是使用 和 标签,但是当我这样做时,它会导致按钮占用与 JToolBar 中剩余的空间一样多的空间即使文本很短并且只占用少量空间。这是我创建按钮的方法。
String buttonText = new String("<html><u>Lesson Plans</u></html>");
JButton lessonButton = new JButton(buttonText);
toolBar.add(lessonButton);
如果我删除标签,那么它会占用适当的空间,但如果我将它们放在其中,则会占用整个工具栏。有人知道发生了什么事吗?
I need to have a button whose text is underlined and the only way I could find to do this in Java was to use and tags, but when I do this, it causes the button to take up as much room as is left in the JToolBar even though the text is short and it should only take up a small amount of space. Here is how I create the Button.
String buttonText = new String("<html><u>Lesson Plans</u></html>");
JButton lessonButton = new JButton(buttonText);
toolBar.add(lessonButton);
If I remove the tags then it takes up the right amount of space but if I have them in there is takes up the entire toolBar. Anyone know what's going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您也许可以通过使用以下方法来解决问题:
否则,您应该能够将字体更改为使用带下划线的字体。 Darryl 的 视觉字体设计器 展示了如何向字体。
You might be able to fix the problem by using:
Otherwise you should be able to just change the font to use an underlined font. Darryl's Visual Font Designer shows how to add attributes to a font.
您可以覆盖 paintComponent 方法,并使用任何样式和字体在其上书写。
You can overwrite the paintComponent method of your JButton, and write on it with any style and font.
您忘记了结束符“”并写了“”......这可能是您出现问题的原因。
You forgot the closing "" and wrote "" instead... This may be the reason for your problems.