I have a JList and JTextArea pair. Based on the selected item on JList, Data will be displayed in JTextArea. But for some data, user inputs are needed, and are collected by a JOptionPane. The problem is when I traverse JList with up and down arrows; having JOptionPane popped up; both successive items are selected. I mean previously selected data is not getting unselected, but only the last data is supposed to be selected. I am popping JOptionPane inside changeTextArea() method and the Code is as follows. Thanks for any help!
private class JListListenerEdit implements ListSelectionListener {
public void valueChanged(ListSelectionEvent event) {
if (!event.getValueIsAdjusting() && listEdit.isFocusOwner()) {
Data selection = null;
try {
selection = listEdit.getSelectedValue();
} catch (Exception e) {
}
if (null != selection) {
changeTextArea(selection);
}
}
}
}
public void changeTextAreaEditData(SData selection) {
if (selection.requireInputs()) {
JOptionPane.showMessageDialog(frame,"Provide inputs to process the data.","Inputs Required", JOptionPane.INFORMATION);
this.textAreaEditData.setText(processData(selection.getData()));
} else {
this.textAreaEditData.setText(selection.getData());
}
}
I see that you are checking
getValueIsAdjusting()in yourListSelectionListener, as shown here. You might try wrapping the call tochangeTextArea()inside anRunnableusinginvokeLater().