jList 中的部分文本应加粗
我可以将部分文本设置为 jList 粗体吗?
在某些组件中,我可以将带有 html 标记的文本设置为粗体,但这里不行..还有其他方法可以做到这一点吗?
can i set a part of the text in a jList bold?
in some component i can set the text with html-marks to bold but not here.. is there any other way to do this?..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JList(在 Metal LAF 中)的默认字体为粗体。因此,您首先需要更改默认字体,然后将 HTML 字符串添加到 ListModel,以仅将您想要显示为粗体的文本加粗。例如:
如果您遇到问题,请发布您的 SSCCE 来演示问题。
The default font is bold for a JList (in the Metal LAF). So you would first need to change the default font and then add your HTML string to the ListModel to only bold the text that you want displayed bold. Something like:
If you have problems then post your SSCCE demonstrating the problem.
您应该能够绑定到
ListCellRenderer
。由于DefaultListCellRenderer
扩展了JLabel
,我希望有某种方法可以嵌入在默认用法中被忽略的 HTML 中。You should be able to tie into the
ListCellRenderer
. Since theDefaultListCellRenderer
extendsJLabel
, I'd expect there to be some way to wedge in HTML that's getting passed over in the default usage.您是否尝试过创建自定义列表单元格渲染器?如果没有,您不妨尝试一下。教程将向您展示如何操作。请看这里:
http://download.oracle.com/javase /tutorial/uiswing/components/list.html
http ://download.oracle.com/javase/tutorial/uiswing/components/list.html#renderer
http://download.oracle.com/javase/tutorial/uiswing/components/combobox.html#renderer
Have you tried creating a custom list cell renderer yet? If not, you may wish to give this a try. The tutorials will show you how. Please have a look here:
http://download.oracle.com/javase/tutorial/uiswing/components/list.html
http://download.oracle.com/javase/tutorial/uiswing/components/list.html#renderer
http://download.oracle.com/javase/tutorial/uiswing/components/combobox.html#renderer