Drew Kabala
Drew Kabala

Reputation: 3

How to make a button stay depressed when clicked in a Swing Java GUI app

This seems like something really simple and yet I can't find any good solutions online. I am making a simple game and in the main frame I have JButtons. What I would like is for when I click a button it stays looking visually depressed and then when I click it again it "pops" back up. I know I need an ActionListener on the button but I can't figure out the code inside of it. I've seen some discussions referencing "setPressed(true);" but as far as I can tell that is not a method on a JButton object, so I don't know how it's useful. Thanks.

Upvotes: 0

Views: 199

Answers (1)

camickr
camickr

Reputation: 324197

You can use a JToggleButton.

Read the section from the Swing tutorial on How to Use Buttons for more information.

Upvotes: 2

Related Questions