开发者

java DefaultListModel

开发者 https://www.devze.com 2023-03-05 07:31 出处:网络
if(incasationBegin > 0) { int anwser = JOptionPane.showConfirmDialog(null, Config.QUESTION,\"Confirm\", JOptionPane.YES_NO_OPTION);
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:

  1. Delay your call to jList0.addListSelectionListener(... in such way that no Listener exists when you call setSelectedIndex.
  2. Have the listener valueChanged method check for some "enabled condition", for example read a boolean isEnabled. Set this condition to false before calling setSelectedIndex and to true after that.
  3. Call jList0.removeListSelectionListener(.. before the call to setSelectedIndex. Add the listener to the list again after the call.
0

精彩评论

暂无评论...
验证码 换一张
取 消