vendredi 19 juillet 2019

When a checkBox is selected, how do I get the text that is assigned to it using e.getStateChanged?

When a checkbox is selected, (using the e.getStateChange()) I want to be able to add the checkboxes text value to an arrayList.

I currently have it that when I press a button on screen, it searches through all checkboxes (around 50 of them) and uses

if (n.isSelected())
{
    arrayList.add(n.getText());
}

Can I have it that when the checkbox is initially selected it will add that items text value, and only that item to the arrayList without having to loop through all of the checkboxes? e.g. something similar to above (but correct) such as

if(e.getStateChange() == ItemEvent.SELECTED)
{
    arrayList.add(getText());
}

If this is possible, is it then possible to then remove the relevant item from the arrayList when the checkbox is subsequently deselected?

I'm new to java so please accept my apologies if this is a daft question!




Aucun commentaire:

Enregistrer un commentaire