Java如何创建不可点击的Jlist

标签 java swing colors jlist

enter image description here

该图片取自netbean,选项1.和2.不可点击。 我在 Jlist 中有类似的设置,但是当我 setenabled(false) 时,该项目变为灰色,我希望它保持黑色,如上所示。

最佳答案

this image is taken from netbean, the option 1. and 2. is not clickable. I have the similiar setup in Jlist but when i setenabled(false) the item become grey, i want it remain black color, like what is shown above.

对于禁用的JList,您可以在UIManager.put("Label.disabledForeground", Color.magenta);

中更改键

编辑

你可以玩

UIManager.put("List.background", Color.lightGray);
UIManager.put("List.selectionBackground", Color.orange);
UIManager.put("List.selectionForeground", Color.blue);
UIManager.put("Label.disabledForeground", Color.magenta);

或者类似的方法也可以在XxxListCellRenderer中重写,而无需为UIManager设置任何值

关于Java如何创建不可点击的Jlist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19400028/

相关文章:

java - 使用相同用户名创建的 2 个用户在执行 "map.get(user);"时可以有相同的结果吗?

对于相同的数据包大小,Java DatagramSocket receive() 比 send() 花费更多时间

java - 应用排序器时删除 JTable 行会导致 IndexOutOfBoundsException

java - Swing - 使用相同的组件弹出菜单更改不同的 JLabel

css - 如何在 GWT 中生成颜色并在 CSS 中动态应用它

java 扫描仪不能在终端工作

java - 如何提取在 java 中声明的字符串并放入 jar 文件中

java - NetBeans 中的文本字段禁用

python - Matplotlib:如何根据 LineCollection 的坐标更改其颜色?

android - 如何在Android中将彩色图像变成黑白