2
I’d like to exhibit a JCheckBox
larger than normal by default interface. After some searches I found in the link Customize Jcheckbox icons an example to be used, but it does not change the size of Jcheckbox, but replaces its default image with other images that will represent its possible states (mouse over the object, mouse outside the object, marked, unchecked, enabled, disabled, etc.). All right, because I downloaded images, edited in order to meet every situation.
I then created a class called ACheckBox
extending JCheckBox
to lock the setting of these images to the JCheckBox
, where the class stood as illustrated below:
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import br.com.alutal.model.Constantes;
public class ACheckBox extends JCheckBox {
private static final long serialVersionUID = 1L;
public ACheckBox() {
super();
this.setIcon(new ImageIcon(Constantes.IMG_CAMINHO_CHECKBOX));
this.setSelectedIcon(new ImageIcon(Constantes.IMG_CAMINHO_CHECKBOX_CHECKED));
this.setDisabledIcon(new ImageIcon(Constantes.IMG_CAMINHO_CHECKBOX_DISABLED));
this.setDisabledSelectedIcon(new ImageIcon(Constantes.IMG_CAMINHO_CHECKBOX_DISABLED_CHECKED));
this.setPressedIcon(new ImageIcon(Constantes.IMG_CAMINHO_CHECKBOX_PRESSED));
this.setRolloverIcon(new ImageIcon(Constantes.IMG_CAMINHO_CHECKBOX_ROLLOVER));
this.setRolloverSelectedIcon(new ImageIcon(Constantes.IMG_CAMINHO_CHECKBOX_ROLLOVER_SELECTED));
}
}
As you can see the path of the images are in the constants, creating objects ImageIcon
as demonstrated in the link specified above.
Finally, when I instate an object ACheckBox
unfortunately nothing happens. No error, and it does not appear in the panel. I do using directly the JCheckBox
there works.
What am I doing wrong? The question of the image path is correct because it is paths used in other functioning objects (such as JButton
for example).
I wonder what it might be?
Check if the image is loading correctly. If you are using netbeans test like this: create a label, go to properties, icon, then click the button and select custom code, and then enter one of your codes:
new ImageIcon(Constantes.IMG_CAMINHO_CHECKBOX)
give ok and see if appears.– Dener
@Dener, I did the test and it is not the image path. I put it in one of the objects
JButton
from the menu and the image appeared normally.– Daniel Chiuratto Seabra
as you add in this panel by dragging and dropping or via code?
– Dener
@Dener, I’m putting via code. I’m developing via Eclipse without using graphic IDE to assemble form.
– Daniel Chiuratto Seabra