• Post Reply Bookmark Topic Watch Topic
  • New Topic

valueChanged() of ListSelectionListener() doesn't run  RSS feed

 
Honzak Troubak
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I don't understand why doesn't work ListSelectionListener in my project.

Here is my code:



When I try debug method getSelectedRow() I can see that doesn't run this part of code:



I use this code in other part of my project and there it works well.

Could anybody explain me where is the problem?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding a listener in an accessor method doesn't look right. Can you explain why you felt the need to do that?

To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.
 
Honzak Troubak
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My explain is easy. I have to check if focus in JTable has been changed. And I found tutorial at http://www.java2s.com/Tutorial/Java/0240__Swing/TableSelectionEventsandListeners.htm page which worked well when I used it first time. Unfortunatly now it is not working.
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not an SSCCE.
 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If no code is calling the getSelectedRow() method, the listener never gets attached. If you call the method twice, two listeners get attached. That's why Darryl is right - you shouldn't attach listeners in accessor methods, but instead use constructors or other initialization code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!