File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issues with JTextArea as cellEditor of JTable Column.

 
nirvan bud
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Here is the custom CellEditor code.




regards,
nirvan
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BeForthrightWhenCrossPostingToOtherSites

OP has been asked to provide a SSCCE in the other forum but has yet to do so.
 
nirvan bud
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,
Sorry about cross-posting. Here is the SSCCE that shows the problem. Please note following.

1. In the SSCCE, I have used JTextArea inside the JTable column without JScrollPane holding it. This will show that you will have to press "Tab" key twice in order to get out of JTable column.

2. If you change the SSCCE to use JScrollPane as container for JTextArea, you will see that pressing the "Tab" key takes the cursor out of the JTable instead of to the next column.


The main JFrame that contains JTable




The Data Oboject that ArrayList needs to back the JTable




The WrappedAction class for setting new action to TAB key (Written by you).




regards,
nirvan
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is NOT a SSCCE.

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:

JTable table = new JTable(10, 5);

Then you add you custom editor to it and start testing. We don't want (or have time) to look at code that is not related to the problem.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And can I remind you of what the other Rob told you. Private message to follow in case you can't remember.
 
nirvan bud
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry once again Rob. This time I am sure it is an SSCCE.

Issue Once again:

1. If the column editor is JTextArea, then after editing the column, it requires two "Tab" key presses to come out of it.

2. If the column editor is JScrollPane with JTextArea inside, then it is not possible to start it editing using the keyboard. It requires use of mouse to start editing.

Here is the code.



regards,
nirvan.
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read your private messages. This is not optional.
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
nirvan bud
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

regards,
nirvan.
 
nirvan bud
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


regards,
nirvan.
 
mark goking
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

http://tech.chitgoks.com/2010/01/28/jtextarea-cell-editor-tab-key-traversal-to-next-cell-in-jtable/
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic