New JList loses the listener.

I have a gui, which I need to update with new lists depending on the selection of the user. The list is being listened to by ListSelectionListener. After I new the JList (for updating with new values). The listener doesn't recognize the source anymore. Any clues as to why?
Code snippet below. getAttrs() function is called
based on some selection by the user. So if the selection changes, this fn will be called.
getAttrs() {
Vector listVec = new Vector();
listVec.add(...
listVec.add(...
attrList = new JList(listVec);
attrList.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent ev) {
Object src = ev.getSource();
System.out.println("src:"+src.toString());
if ( src == attrList ) {
if (!ev.getValueIsAdjusting()) {
Object[] selectedObjs = ((JList)src).getSelectedValues();
if (selectedObjs.length > 1) {
System.out.println("multi objects");
else {
String attrName = (String)selectedObjs[0];
System.out.println("attr"+attrName);
setDetailValues(attrName);
else {
System.out.println("value is still changing");
else {
System.out.println("not attrList");
What happens is that first time, it works oks and recognozes the src. next time (when the user selection changes and this function is called again) it says "not attrList" meaning it doesnt' reconize the src.

Where do you add the JList? It looks like you added the first JList to a Container. The next time through this method, you are changing only the attrList reference, not the original and different JList object that you added. I think the original listener is what's being called, and since the old JList is calling the listener, the source is not the same as the attrList JList.
Instead of making a new JList, you should update the original JList that you added.

Similar Messages

Maybe you are looking for

  • How do I control my airport extremes/time capsules w/airport utility over the internet without mobile me? iCloud has disabled this function.

    How do I use airport utillity with Time Capsule(or any airport extreme) over the internet without mobile me? iCloud has disabled this function. The mac's that I have not upgraded to icloud still see my routers over the internet with mobile me enabled

  • Database Connection error in Crystal Reports using SAP BW system

    Hi, While using Crystal Reports in trying to build a report on the SAP Query in SAP/BW System using the MDX driver, I am able to get the structure of the query fields into the report but on the other hand while trying to refresh the report for data I

  • Why is unread messages not updated in mail.app until restart

    I have imap accounts in mail.app and on my iPhone and my iPod Touch and they are are all setup the same. If I read a msg on the mail.app, it is marked as read correctly and this also shows up on the iPhone and the iPod. But if I read the msg any othe

  • Foreach loop

    Hello, I am trying to convert a normal for loop to the new foreach loop. I was able to do one function that prints every element, but can't seem to be able to modify the elements in the array. //This works ok public static void printjoy(int [][] arra

  • Printouts are faint in Mountain Lion

    I recently upgraded from 10.6.8 to 10.8.3.  Even with new drivers from the Canon website, my PIXMA MP490 printouts are faint.  Printouts are perfect if I reboot from 10.6.8 backup drive.  How to control print quality in 10.8.3?  Am I missing a settin