cay
cay

Reputation:

JButton question

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?

Upvotes: 1

Views: 1018

Answers (2)

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147164

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.

Upvotes: 1

Bombe
Bombe

Reputation: 83852

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.

Upvotes: 3

Related Questions