I just reproduced your described behavior using this source:
import java.awt.Image;
import javax.swing.*;
import javax.imageio.ImageIO;
import java.net.URL;
class RadioWithImage {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.gravatar.com/avatar/" +
"a1ab0af4997654345d7a949877f8037e?s=128");
Image image = ImageIO.read(url);
final ImageIcon imageIcon = new ImageIcon(image);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JRadioButton radioButton = new JRadioButton("A.T.", imageIcon);
JOptionPane.showMessageDialog(null, radioButton);
}
});
}
}
It seems like a bug to me, though I cannot recall seeing a radio with an icon. How are they supposed to look?
Time to reach into my 'box of hacks'.
import javax.swing.*;
class RadioWithImage {
public static void main(String[] args) throws Exception {
String url = "http://www.gravatar.com/avatar/" +
"a1ab0af4997654345d7a949877f8037e?s=128";
final String html = "<html><body><img src='" +
url +
"' width=128 height=128>";
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JRadioButton radioButton = new JRadioButton(html);
JOptionPane.showMessageDialog(null, radioButton);
}
});
}
}
This technique will not work if:
- The use-case requires other types of icons (pressed, roll-over, selected etc.)
- The button is disabled (it will render incorrectly).