Corect use of a dropDown in swing

Hi to everyone. Recently i noticed a problem when a user interact with the Drop Down created in Swing.
On the Html the select of a specific item on the drop down is managed by a SELECT EVENT which is called only when a item is select.

On the moment i didn’t find an analog method on Swing examples. It’s possible to use an action listener or a mouse listener but it isn’t the right way because in this listener are invoked multiple time in the program execution like open view, close view , fill drop down operation and so on.
My question which is the corect way to use drop down in swing ?

Solved

takeEoat.addItemListener(new ItemListener() {

@Override
public void itemStateChanged(ItemEvent e) {
	// TODO Auto-generated method stub
	if(e.getStateChange()==ItemEvent.SELECTED) {
	try {
	provider.get().saveTake(provider.get().getIndexOfSelectedKit(takeEoat.getSelectedItem().toString(), installation.dataModel));
	provider.get().controllPositions();
	leftVerticalBox.updateUI();
	}catch (Exception e1) {
		// TODO: handle exception
	}
	}
}

});

1 Like