aspose file tools
The moose likes Swing / AWT / SWT and the fly likes JList valueChanged not recognizing DefaultListModel Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "JList valueChanged not recognizing DefaultListModel" Watch "JList valueChanged not recognizing DefaultListModel" New topic
Author

JList valueChanged not recognizing DefaultListModel

Bill Sherlock
Greenhorn

Joined: Nov 27, 2001
Posts: 3
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


They that can give up essential liberty to obtain a little temporary safety<BR>deserve neither liberty nor safety.<BR> --Benjamin Franklin
Qusay Jaafar
Ranch Hand

Joined: May 06, 2002
Posts: 127
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


Qusay
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JList valueChanged not recognizing DefaultListModel
 
Similar Threads
JList & Observer
Restrict drops to JPanel where it's drags are from.
about JList
Need help with JList selection modes
How to add a String array to JList?