简体   繁体   English

如何更改JList中文本的颜色和样式?

[英]How to change the color and style of text in a JList?

I have a DefaultListModel that contains a list of names. 我有一个DefaultListModel,其中包含名称列表。 When the names are added to the list, they are just added as Strings. 将名称添加到列表时,它们只是作为字符串添加。 What I need to do is change the color / style (ie, italicize) of some of the names at certain times. 我需要做的是在某些时候更改某些名称的颜色/样式(即,斜体)。 Is there any efficient way of doing this? 有什么有效的方法吗?

You need to use a custom renderer. 您需要使用自定义渲染器。 See Writing a Custom Renderer . 请参阅编写自定义渲染器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM