if(incasationBegin > 0)
{
int anwser = JOptionPane.showConfirmDialog(null, Config.QUESTION,"Confirm", JOptionPane.YES_NO_OPTION);
if(anwser 开发者_Go百科== 1)
{
jList0.setSelectedIndex(incasationBegin);
return;
}
}
incasationBegin = jList0.getSelectedIndex();
How do I setSelectedIndex
without calling jList0ListSelectionValueChanged
action? Because when I click on option confirm popup and when I click NO, the new item is still selected. I have tried to add incasationBegin =0;
before return, but then on first click confirm popup.
Let me see if i understood you correctly. You are adding a ListSelectionListener
to the JList
and want to prevent your call to setSelectedIndex
from firing the valueChanged
event, is that it?
You can try a lot of different approaches here:
- Delay your call to
jList0.addListSelectionListener(...
in such way that no Listener exists when you callsetSelectedIndex
. - Have the listener
valueChanged
method check for some "enabled condition", for example read aboolean isEnabled
. Set this condition to false before callingsetSelectedIndex
and to true after that. - Call
jList0.removeListSelectionListener(..
before the call tosetSelectedIndex
. Add the listener to the list again after the call.
精彩评论