Mike2012
Mike2012

Reputation: 7725

Making a JButton stay depressed manually

I would like to make a JButton stay pressed down and not be able to be pressed again until some event occurs is there an easy way to do this?

Upvotes: 2

Views: 5859

Answers (3)

Vincent B.
Vincent B.

Reputation: 514

I think you should have a look at the JButton Swing class Here. It allows you to have a 2 state button, and so for what you need, you may just need to attach your button to some boolean, allowing it to be selected or not.

Upvotes: 2

Benjamin Cox
Benjamin Cox

Reputation: 6120

You should probably look at the JToggleButton class. Associate it with an Action which calls setEnabled(false) to disable interaction.

Once your event happens you call setEnabled(true) and setSelected(false) to restore the original state of the button.

Upvotes: 7

Adam Goode
Adam Goode

Reputation: 7468

Perhaps you just want to disable the button? Try setEnabled(false) in your callback for the button.

Upvotes: 4

Related Questions