Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JRadioButtons with Icons

Status
Not open for further replies.

pipk

Programmer
Feb 20, 2001
455
GB
Does anyone know why, when I create JRadioButtons with just an Icon file, the actual radio buttons no longer appear on screen?? Are my icons perhaps too big (32 x 32)?

Here is the code that creates them, the variables are all declared globally earlier on.

private void addFaces()
{
facePanel = new JPanel(new GridLayout(3, 1));
Icon happyIcon = new ImageIcon("happy.jpg");
Icon apathyIcon = new ImageIcon("indifferent.jpg");
Icon sadIcon = new ImageIcon("sad.jpg");

happyButton = new JRadioButton("Good", happyIcon);
apathyButton = new JRadioButton("Neither", apathyIcon);
sadButton = new JRadioButton("Bad", sadIcon);

faceButtonGroup = new ButtonGroup();

faceButtonGroup.add(happyButton);
faceButtonGroup.add(apathyButton);
faceButtonGroup.add(sadButton);

facePanel.add(happyButton);
facePanel.add(apathyButton);
facePanel.add(sadButton);

}

The facepanel is then added to another JPanel(with a flow layout), which in turn is added to another panel (border layout). The icons and strings appear no problem at all, but the actual radio buttons themselves have disappeared??

Many thanks for any help.
 
Hi pipk,

From what I see, when you add an icon to a RadioButton, it replaces the default icon instead. This means the 'circle' thing that you see is actually an icon itself. So when you create a RadioButton object and pass in an Icon, it replaces the default icon, which is the circle, with the icon you passed in.

I don't know if there are any other ways... but perhaps you would like to paint your icon instead?

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Cheers Leon, I think you are right. What a pain!! Took me ages to draw those Icons as well, D'OH.
 
Hi pipk,

Sorry to hear that you took a long time to draw those icons, but at least you know what is the problem now :)

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top