I am trying to use JTextArea as a cellEditor for a JTextArea column. I created a custom CellEditor for the purpose. But when I use the JTextArea component I get a few issues.
1. The JTextArea default "Tab" key operation does not take the cursor out of the textarea. To avoid this I used
textArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,new Tab Key). This solved my problem.
2. To come out of the textArea column into the next column, I have to press the "Tab" key twice. I have not been able to solve this problem.
3. Since I am using JTextArea, I want to use JScrollPane with JTextArea in it instead. But when I use JScrollPane with JTextArea in it pressing the "Tab" key takes focus out of the JTable, instead of traversing to the next column. I haven't been able to solve this problem too.
Your question is about a custom cell editor. Your code includes a custom TableModel and custom data class. Those are irrelevant for testing a cell editor. Maybe the model or data class is causing the problem so get rid of them. It takes one line of code to create a JTable:
Well, there are actually more than 2 InputMaps for the text area so you need to loop through all of them to make sure the binding is removed.
Joined: Dec 27, 2008
I have resolved the problem no 1 presented in the last SSCCE post. Now the only problem is (problem no 2) that when I add scrollPane (with JTextArea in it), instead of directly adding JTextArea to the JTable, the column cannot be edited by keyboard i.e. it requires a mouse click.
Joined: Dec 27, 2008
I implemented focus listener on the Custom cell editor class to find where exactly the focus is going when using keyboard. When scrollPane is used instead of directly adding JTextarea, the focus goes to scrollPane and not the JTextArea and hence I am not able to edit the cell. Surprisingly, when mouse is directly used over the cell to gain focus, the Jtextarea gets the focus !.
I tried to use table.setSurrendersFocusOnKeystroke(true) but that doesn't solve the problem.
If anyone knows how to set focus to the child component of jscrollpane preferrably without using Focus Traversal Policy, please let me know.
this thread is not that very old so i will reply. in case you are interested nirvan bud, i created a TextAreaCellEditor class that traps the TAB key event and transfers focus to the next cell of the JTable.
in this case, the TAB key will loop through all cells of the JTable endlessly, meaning, if it is at the last column and last row of the JTable, the TAB key will then focus the 1st row and 1st column.