I have a custom renderer/editor that uses a JTextField. I click w/ the mouse on a cell...the cell is "selected" but no caret is visible. I enter text and it appears at the end of the String, but still no caret. What I want is to click on a cell and the cell become editable w/ the caret positioned where the mouse click occured. Suggestions?
By default, the cursor will appear when the cell is double clicked. I don't know, if it would help to set the DefaultCellEditor.setClickCountToStart() to 1. Of course, that will work only in the case you are using the DefaultCellEditor or a subclass of it. Another possibility might be, to set the caret of the Editor (as a subclass of JTextField/JTextComponent) explicitely). there most likely is some method in the API that does this. If not in the JTextComponent hierarchy than in Document or its subclasses (something like setCaret(int position)). Chantal
Okay, the code below does what I want. I'd have thought there would be some way form me to call setClickCountToStart() on the system-supplied DefaultCellEditor rather than creating a new one, but I couldn't find it.
TableColumn col = envtable.getColumnModel().getColumn(1); DefaultCellEditor singleclick = new DefaultCellEditor(new JTextField()); singleclick.setClickCountToStart(1); col.setCellEditor (singleclick);