• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable problem

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a JTable.. When we select one particular row in it and press Enter I want to get hold of the row that has been selected... I added a Key Listener to my table and looking for Enter key.

The moment when the Enter key is pressed and in my listener when I call m_table. getSelectedRow(), it gives me the next row. Like when we select row '1' and press enter, table.getSelectedRow() gives '2'.

In my key Listener i override keyReleased to catch the Enter Event.

Any help on this ASAP.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Karthick Dharani Vidhya:

Any help on this ASAP.



Ease Up.

This is the default table behavior. If you have observed the row jumping is cyclic. If you hit enter when the last row is selected, it will select the first row.

Now since you know it jumps a row, you can either call the getSelectedRow and subtract 1 from it or, trap the keyPressed event instead of the keyReleased as the keyPressed will give you the correct row selection.

PS. There might be a solution in playing around with key bindings. It is up to you to decide if it is worth the effort.
[ August 05, 2008: Message edited by: Maneesh Godbole ]
 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was able to do it yest. Sorry forgot to update.

I did the same thing like getting the selectedRow from table and sub 1 from that.

But this sounded bit buggy. One more way is to override KeyPressed instead of keyReleased. When we do this, getSelectedRow gives you the row where we pressed enter.
reply
    Bookmark Topic Watch Topic
  • New Topic