Custom JCheckBox does not appear

2

I would like to display a% cos_de% larger than normal by interface standard. After some searches I found the Customize JCheckBox icons an example to use, but it does not changes the size of the JCheckBox, but instead 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, I edited them to fit each situation.

I then created a class called JCheckBox that extends ACheckBox to lock the definition of those images to JCheckBox , where the class is as follows:

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 JCheckBox objects as demonstrated in the previously specified link.

Anyway, when I instantiate a ImageIcon object unfortunately nothing happens. Neither error, and it does not appear in the panel. If I do it directly using ACheckBox it works there.

What am I doing wrong? The image path question is correct because they are paths used in other objects that work (like JCheckBox for example).

What can it be?

    
asked by anonymous 16.07.2015 / 06:20

1 answer

0

Daniel ,

I suppose you're adding your checkBox with a jPanel.add(aCheckBox); and your dashboard has a layout livre .

In this way, the layout of your jPainel does not know where to add your component (by right, left, top, bottom, middle, ...).

Note that if you drag and drop the class of your component in the panel if you are using NetBeans your checkBox will appear, or even change the layout of jPanel to other layouts (Flow, Box, Grid etc) and using jPanel.add(aCheckBox); will appear normally.

% void with free design uses JPanel , if you do not want to change the GroupLayout of your panel to one of the ones I mentioned above, you will have to add% (Give a look here how to use it!)

    
22.07.2015 / 15:35