vendredi 18 septembre 2015

JTable Checkbox listener doesnt work properly

I have a JTable which have Checkboxes. This table implements the listener tableChanged, which fires an event selectionChanged with true or false if the Checkbox is selected or not.

In the selectionChanged, there is a counter to know how many checkboxes are checked. But this doesnt work properly. If i click anywhere on the checkbox it also increases the counter.

This is how it looks like:

@Override
    public void tableChanged(TableModelEvent P_evt)
    {
    .....
    listener.selectionChanged(F_newValue);

@Override
    public void selectionChanged(boolean P_selected)
    {
        if (P_selected)
        {
            nextButton.setEnabled(true);
            selectedBundles++;
            System.out.println("Selected Bundles: " + selectedBundles);
        }
        if(!P_selected)
        {
            nextButton.setEnabled(false);
            selectedBundles--;
            System.out.println("Selected Bundles: " + selectedBundles);
        }
        if (selectedBundles > 0)
        {
            nextButton.setEnabled(true);
        }
        else
        {
            nextButton.setEnabled(false);
        }




Aucun commentaire:

Enregistrer un commentaire