Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Select vs Edit in JTable

 
G Estes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to programatically select and edit a cell in a JTable. The cell editor and renderer are JTextField components. My code is as follows:

What I get is a cell that appears selected, but the cursor is not present. If I type, text is added to the end of the text field, but still no cursor. If I click the cell, the cursor appears where I click and when I type, text appears at the point of the cursor within the text string.
What I want is to have the cell selected (current behavior) AND have the cursor appear at the end of the text string in the cell, ready for editing. Additionally, I'd like the entire text to be selected within the cell so typing replaces the current text.
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setCaretPostition (or other related methods) from JTextComponent.
Bill
 
G Estes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I tried this and got the same results. I think that the problem is with the actual "selection" vs "editing" state of the cell. If it's editing, then the caret should be visible, shouldn't it? It's almost like some event that needs to be fired, isn't.
[ November 05, 2002: Message edited by: Gil Estes ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic