Java Radio Buttons

B

bwilde

Hello,

I am creating a GUI in Java and would like to make buttons that behave
like radio buttons but look like regular JButtons. That is, I would
like for there to be a button group of three rectangular buttons, with
one of them always selected (and displayed differently as the other
to). When another button is clicked, I would like to unselect the
previous one and select the current one.

The closest thing that I have seen to do this is to play around with
the icons that are used for radio buttons (although I don't think that
java lets me add new text to these images). It seems like there should
be a simpler way of doing this, though.

Any thoughts?

Thanks.
 
L

Lee Weiner

Hello,

I am creating a GUI in Java and would like to make buttons that behave
like radio buttons but look like regular JButtons. That is, I would
like for there to be a button group of three rectangular buttons, with
one of them always selected (and displayed differently as the other
to). When another button is clicked, I would like to unselect the
previous one and select the current one.

The closest thing that I have seen to do this is to play around with
the icons that are used for radio buttons (although I don't think that
java lets me add new text to these images). It seems like there should
be a simpler way of doing this, though.


There is. If you use JToggleButtons and add them to a ButtonGroup, they will
look like JButtons and act like JRadioButtons.

Lee Weiner
lee AT leeweiner DOT org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top