Hi,
I need to set the background color of a JComboBox when the combo is
disabled. JComboBox.setBackground() works when the combo is enabled,
but it doesn't when the combo gets disabled.
I tried defining a renderer, but the renderer mainly controls the
rendering of the items in the combo's popup list. And again, whether
using a renderer or not, this has no effect on the combo's background
color.
It also thought about keeping the combo always enabled, just making it
"appear" disabled to the user when the combo gets "disabled".
This would require esentially the follwing:
(1) disabling focusabiliy of the combo
(2) avoiding the combo's popup list to show up
The problem here is point (2).
A MouseListener does not work here because it intercepts mouse clicks
after they occurred.
I tried adding a PopupMenuListener to the combo in order to get
informed when the popup list will be displayed. The problem is that a
PopupMenuEvent used in PopupMenuListener's popupMenuWillBecomeVisible()
has no cancel method like input events. So I know when the popup list
gets displayed but I don't know how to prevent this showing up. I tried
to use JComboBox.hidePopup() in the event handler, but this only keeps
the popup list displayed, once it gets shown.
Thanks for reading this.
I would be great if somebody could help me.
Christian Kaufhold - 31 Mar 2005 16:46 GMT
> I need to set the background color of a JComboBox when the combo is
> disabled. JComboBox.setBackground() works when the combo is enabled,
[quoted text clipped - 4 lines]
> using a renderer or not, this has no effect on the combo's background
> color.
http://groups-beta.google.com/group/comp.lang.java.gui/msg/6cf1fb7bde6adae2
http://groups-beta.google.com/group/comp.lang.java.gui/msg/76a6ab755da9093d?dmod
e=source
(for an unknown reason, my posting is missing from that thread).
Christian