File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Select vs Edit in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Select vs Edit in JTable" Watch "Select vs Edit in JTable" New topic

Select vs Edit in JTable

G Estes
Ranch Hand

Joined: Oct 22, 2002
Posts: 62
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

Joined: Oct 16, 2002
Posts: 88
Try setCaretPostition (or other related methods) from JTextComponent.
G Estes
Ranch Hand

Joined: Oct 22, 2002
Posts: 62
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 ]
I agree. Here's the link:
subject: Select vs Edit in JTable
It's not a secret anymore!