How can I have a ceckbox grup with image?
I use:
for (String testata : listaTestate) {
JCheckBox checkbox = new JCheckBox();
ImageIcon imgTestata = new ImageIcon("src/img/"+testata+".png");
checkbox.setName(testata);
checkbox.setBackground(new Color(194, 169, 221));
checkbox.setSelected(true);
testate.add(checkbox);
JLabel label = new JLabel(imgTestata);
label.setBackground(new Color(194, 169, 221));
label.setPreferredSize(new Dimension(500, 50));
testate.add(label);
}
but a lot of space between the ImageIcon and the JCheckBox
Aryan Kumar
04-Jul-2023To work with a JCheckBox with image in Java, you can use the following steps:
Here is an example of how to work with a JCheckBox with image in Java:
Java
This code will create a JFrame with a JCheckBox with image. The JCheckBox will be located at (100, 100) and have a size of 100 x 100. The text of the JCheckBox will be "Check Box" and the image of the JCheckBox will be "check_box.png". When the JCheckBox is checked, the following message will be printed to the console: "The checkbox is checked".
Anonymous User
04-Feb-2015Without knowing the layout manager, it's difficult to be 100%, but if I was doing this, I might use a GridBagLayout...