1
if(incasationBegin > 0)
{
  int anwser = JOptionPane.showConfirmDialog(null, Config.QUESTION,"Confirm", JOptionPane.YES_NO_OPTION);
  if(anwser == 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.

3
  • 1
    Even with the code and explanation, I still don't follow you. Can you please elaborate or make your explanation more clear/concise? Commented May 11, 2011 at 13:45
  • after calling jList0.setSelectedIndex(incasationBegin); this the action jList0ListSelectionValueChanged is called, and I dont want that, is it possible ?? Commented May 11, 2011 at 13:49
  • Well, valueChanged is triggered whenever selection/deselection is done. So, not wanting this to happen seems very unnatural. Anyway, a little bit of browsing landed me the following link - stackoverflow.com/questions/3092834/… Commented May 11, 2011 at 14:01

1 Answer 1

2

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.