Search code examples
javaswingjbuttonrendererjradiobutton

JRadioButton that looks like JButton


I'm trying to create a feature similar to that of Geogebra's toolbar: it has buttons that select tools, so only one can be selected at a time, but they don't look like radio buttons (a dot, with an inner dot if it's selected); they look like JButtons with an ImageIcon.

I've gone through some of the source (specifically ModeToggleMenu.java and Toolbar.java) but still can't quite figure out what's happening. I just need something basic. I would really appreaciate help!

Screenshot of what I mean:

An image of Geogebra's toolbar

Note the pointer, point, line, perpendicular line, triangle, etc.. That's the effect I'm trying to achieve.

Thanks very much!


Solution

  • Create custom icons then use:

    radioButton.setIcon(...);
    radioBbutton.setSelectedIcon(...);