0

The title says it all. I'm attempting to add a checkbox with both text and an icon displayed next to the checkbox. Here is my class code:

public class MyDialog extends JDialog
{
    public MyDialog(Dialog owner, String title)
    {
        super(owner, title, true);
        JPanel mainPanel = new JPanel(new FlowLayout());
        JCheckBox box = new JCheckBox();
        box.setIcon(new ImageIcon("path/to/icon.svg"));
        box.setText("Checkbox");
        mainPanel.add(box);
        this.add(mainPanel);
        this.setSize(new Dimension(500, 500));
        this.setVisible(true);
    }
}

I would have expected that, upon construction of a new MyDialog instance, it would display the icon, some text and, well, a checkbox. However, only the icon and the text are displayed. Am I missing something here? Thanks!

wickstopher
  • 981
  • 6
  • 18
  • Afaik if you set the Icon, you replace the square with that icon... – Ueli Hofstetter Apr 30 '15 at 20:37
  • 1
    The icon replaces the button. See my proposed duplicate. – durron597 Apr 30 '15 at 20:37
  • This is because the checkbox *was* the icon. I encountered this once. To fix, you've got to find the icons (unchecked and check) in the jre - It's somewhere under .plat or .platf if I remember correctly - and combine the two images / icons to make the icon you want. – ControlAltDel Apr 30 '15 at 20:38
  • yep, thanks for the dup, that's my question exactly, just didn't show up in my searches. i'll close this one. – wickstopher Apr 30 '15 at 20:38

0 Answers0