views:

122

answers:

2

Can you disable a JButton without graying out the button itself? When you use setEnbaled(false), the button disables and turns to gray. Is it possible to disable the button but make the appearance of the button still the same?

+3  A: 

You could ignore the button press in your ActionListener if a flag is set; however, you should not disable the button without showing it as disabled: it will only confuse the users of your application.

Bombe
+1  A: 

I suggest setting a ButtonModel with overridden setArmed and setPressed. Exactly how you override it depends on exactly what you want it to do - should it appear to be pressed when pressed, for instance? Only set the ButtonModel once for a JButton. Add or repurpose state on the ButtonModel to indicate how you want it o behave at any given moment.

Clearly, GUIs with non-standard behaviour are likely to confuse users.

Tom Hawtin - tackline