Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在 JList 组件中加粗一行以显示活动行。应该动态完成以让用户立即看到活动行中的更改。我怎样才能做到这一点?
查看渲染器中的 CustomCellRenderer,您可以根据 isSelected 参数更改显示标签的颜色。
万一您想更改所选项目的颜色,您可以使用:
list.setSelectionForeground(Color.RED);
还有另一个类似的 API 用于设置所选项目的背景:
list.setSelectionBackground(Color.BLUE);