Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 157739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:33:27+00:00 2026-05-11T10:33:27+00:00

I have a JList with some items. I’ve added a listener for when a

  • 0

I have a JList with some items. I’ve added a listener for when a item in the list is selected. Here is the code for what happens when an item in the list is selected:

private void questionaireNamesListValueChanged(ListSelectionEvent evt) {     try {         inputPanel.setEnabled(false);         inputPanel.setVisible(false);         inputTextField.setText('');         inputStatusLabel.setText('');         int questionaireIndex = questionaireNamesList.getSelectedIndex();          // Why will this be printed twice?         System.out.println('Questionaire Index: ' + questionaireIndex);          if (remoteQuestionServer.getQuestionCount(questionaireIndex) == 5) {             answerQuestionButton.setEnabled(true);             addQuestionButton.setEnabled(false);         } else {             addQuestionButton.setEnabled(true);             answerQuestionButton.setEnabled(false);         }     } catch (RemoteException ex) {         ex.printStackTrace();     } }  

As you can above I put a System.out.print statement in and every time I click on something in the list I get two ouputs for that item, eg.

Questionaire Index: 4 Questionaire Index: 4 Questionaire Index: 2 Questionaire Index: 2 Questionaire Index: 0 Questionaire Index: 0 Questionaire Index: 2 Questionaire Index: 2 

Any idea why this is happening?

Thanks, Patrick

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:33:28+00:00Added an answer on May 11, 2026 at 10:33 am

    When you change a selection, one or two events can occur, depending on the implementation. If index #4 is selected and you click on the second item, then the following occurs:

    • First, index #4 is UNSELECTED. Depending on the model, questionaireNamesList.getSelectedIndex() can legally return either 2 or -1.
    • second, index #2 is SELECTED. At this point, questionaireNamesList.getSelectedIndex() will surely return 2.

    Thus, there are two events fired. The definition of how these events are generated allows leeway for different JVM implementations do go things slightly differently.

    NOTE: You should probably check the value of ListSelectionEvent#getValueIsAdjusting() to see if the event you are processing is one in a series of events. You probably need to ignore all events where this returns true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have a JList listen to list selection listener. private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt)
I have a JList and JTextArea pair. Based on the selected item on JList
I have a JList, and a JButton, user can click an item in the
I have a JList inside a Scrollpane. If you click on the list and
I have a JList with a key listener to make it easy for the
I want to code two JList (categories and items). When I click one category
I came across some java code for doing a prefix search on a JList.
I have some VB code which makes use of a COM api and results
I have a JList with items that I want to show two values. Is
I have a JList, wich must display more than 3000 items. I wish to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.