• Post Reply Bookmark Topic Watch Topic
  • New Topic

JList valueChanged not recognizing DefaultListModel  RSS feed

 
Bill Sherlock
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a JList that is displaying a DefaultListModel that is populated via the press of a button. The model is initially empty. I have also declared a variable outside of valueChanged that I need to reset inside the valueChanged method. Here are the pertinent parts of my code:

I know the model is populated because I do a S.o.p and the elements print out as expected. However, when I click on one of the lines in the JList getSelectedValue() returns null.
Any hints would be greatly appreciated!
Bill
 
Qusay Jaafar
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
That's because you did not select any item from the list. getSelectedValue() looks for a selected item and return that Object, when never find a selected item will return null...
Regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!