• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Radiobutton circle disappears when using icon

 
Patrik Nilsson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to have a JRadioButton with an icon but when I create this I only get the Icon, there is no circle to check.

JRadioButton myButton = new JRadioButton(myIcon, true);

The icon is a radiobutton but it is hard to see if it is selected or not.

Is this the way it should be and if so is there a good solution to solve this to get the circle next to the image?

I thought about adding one radioButton and one label with the icon next to each other but is this really the best way to solve the problem???

JRadioButton myButton = new JRadioButton("");
JLabel myLabel = new JLabel();
myLabel.setIcon(aImageIconUnSelectedAll);
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the circle is an icon, so specifying 'the icon' replaces the circle.

> I thought about adding one radioButton and one label with the icon next to
> each other but is this really the best way to solve the problem???

probably is the simplest way.

here's an example of radioButton with textArea - modify for JLabel

http://www.coderanch.com/t/416064/GUI/java/JTextArea-As-JRadioButton
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another approach could be to create a compound Icon consisting of the default and custom icons side by side (requires much more customization if it is to work with all orientations and text positions, setPressed/SelectedIcon etc.)

TestIcon can be replaced with any Icon.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic