This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ListSelectionListener / EventListener not detecting change in rows (up/down) on JTable  RSS feed

 
Kenneth Islington
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have made a JTable which has a ListSelectionListener and when I try and change a value (using a method to change the value on mouse click) it works if you go across the row but when you go straight down or up the value does not get added.
Do i need a seperate listener for this?
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand your functionality.

Post a SSCCE that demonstrates the problem.
 
Kenneth Islington
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so I have semi - figured it out but its by no means perfect.



So basicly one of the event listeners checks to see if the selected cell moves rows and the other checks to see if it moves columns.

Should the //DO SOMETHING bit just be a method? Or is there a way to write to two event listeners into one?

Many thanks
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still have no idea what your question is about and you still haven't posted a SCCE demonstrating the problem.

 
Kenneth Islington
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Heres some compilable code I just put together - if you click in a cell it will be marked "T", you can click in a cell to the left or right to it and it will also be marked "T", however if you try and click in the cell above or below the one you original marked (straight after marking it) it does not get marked "T" unless you click away from the original cell first.
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all class names should start with an upper case character. I know this is a SSCCE but there is no reason to be sloppy.

Now that is a much better question, I actually understand what you are doing and the explanation helps me understand how to test the code.

From your original question I had no idea you were using cell selection (as oppose to the default of row selection) and that the ListSelectionListener was being added to the TableColumnModel. Usually people add the ListSelectionListener to the table to handle row selection.

Anyway, to answer your basic question you can add another ListSelectionListener to the table to handle row selection:



Or, instead of using listeners you could override the changeSelection(...) method of the JTable:


You will almost always get a better answer faster when you include a SSCCE with the question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!