• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

How to goto a particular row /column in JTable

Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I need to know ho to programmatically take my cursor to a particular cell in my JTable.
Also, I am using a defaultCellEditor with textfield for my JTable cells. When I put my cursor on the cell, the text is not highlighted, which I thought is standard behavior. So, overwriting the text is not automatic. I have to use backspace to erase all the text and type in new text. I need to know if there is any fix for this.
Also, my left and right arrows are not working within the cell. Instead of moving the cursor position within the cell, cursor is going to the next item in the row. Is this the standard behavior?
thanks in advance..
-- rambo
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. programmatically starting cell editing:
JTable.editCellAt(int row, int col)
2. obviously it's not standard behaviour. to select the cell value you have to write your own tablecelleditor (or better: extend the Default editor) and add the selecting of the value to the exisiting implementation.
3. there are two states of editing (why? - I don't know):
3.1 by default editing mode starts with one click - but no caret appears. nevertheless it is possible to type letters and use backspace.
3.2 a doubleclick invokes the "real" JTextField behaviour: the caret appears and the cursor keys work as expected.
you can change the click count to start in the DefaultTableCellEditor.
Rambo Rambabu
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. editCellAt doesn't take my cursor to that row/cell. Just to give a background, I am doing a vlidation when some leaves a row. If validation fails, I want to show and alert and take back the cursor to that row/cell. I am pasting part of my code..

if (incentive.equals("X")){
"This Passcode is invalid for the office being processed. Please reenter.",
"Invalid Passcode!",
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is "not a bug", but they provide a workaround:

if (table.editCellAt(row, column))

There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic