• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to goto a particular row /column in JTable  RSS feed

 
Rambo Rambabu
Greenhorn
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
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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.
Chantal
 
Rambo Rambabu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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")){
messagePane.showMessageDialog(
Handlers.PASSCODECORRECTIONPANEL,
"This Passcode is invalid for the office being processed. Please reenter.",
"Invalid Passcode!",
JOptionPane.ERROR_MESSAGE);
Handlers.PASSCODECORRECTIONPANEL.getOrderDetailsScrollPaneTable().editCellAt(Integer.parseInt(rowNumber),5);
 
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:
http://developer.java.sun.com/developer/bugParade/bugs/4224061.html

if (table.editCellAt(row, column))
{
table.getEditorComponent().requestFocus();
}

chantal
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!