该图片取自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/