By default, pressing the TAB key in a JTextArea will insert a tab character instead of transferring focus to the next focusable component. But if your JTextArea is a cell editor within a JTable, and you want the TAB key to transfer to the next cell on an on, what I did was add a KeyListener to the JTextArea and capture the TAB key event when pressed, then calling the JTable changeSelection() method to transfer focus to the next cell.

If the focus was on the last column of a row, it will check if there is another row next to it. If there is, focus will be transferred to the next row on the first column and so on and so forth. Here is the source code for my TextAreaCellEditor class.

If you want the TextAreaCellEditor class to implement trapping the TAB key event, just supply a boolean parameter true to the constructor.

Related Posts Plugin for WordPress, Blogger...