my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Radiobutton circle disappears when using icon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Radiobutton circle disappears when using icon" Watch "Radiobutton circle disappears when using icon" New topic
Author

Radiobutton circle disappears when using icon

Patrik Nilsson
Ranch Hand

Joined: Oct 05, 2004
Posts: 49
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);


Sun Certified Java Programmer<br />Sun Certified Web Component Developer<br />IBM Certified Enterprise Developer
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: May 03, 2008
Posts: 4523
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Radiobutton circle disappears when using icon
 
Similar Threads
RadioButton with no select circle?
10 shuffling question
JComponent text in some JApplets don't show on Mac, do show on Windows PC
Resizing JRadioButton
basic radiobutton question