3

In my JTable, I want to edit all relevant cells like in Excel.

I implemented that ENTER stops editing the cell and transfers focus to the next cell. However, when I hit ENTER in the last cell, the focus cycle makes me jump to the fist cell. But I want to continue outside the table and set focus to a JButton.

How can I break this cycle?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Florian Ruh
  • 110
  • 8

1 Answers1

3

JTable is not a spreadsheet, but setCellSelectionEnabled() should allow you to proceed. Use setDefaultButton() as required, for example.

Addendum: In addition to setDefaultButton(), you can evoke any desired action in your custom Action, as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks. In your example, hitting ENTER always shows the dialog. However, I want to go to the next cell with ENTER. If it is the last one, I want to go to the JButton outside. – Florian Ruh Jul 03 '13 at 14:54
  • I don't understand; if the button is the default button, you don't _have_ to change focus. You can evoke any desired navigation action in your custom `Action`, as shown [here](http://stackoverflow.com/a/9095442/230513). – trashgod Jul 03 '13 at 15:12
  • Oh, using a custom Action is the missing part for my table! Thanks! – Florian Ruh Jul 11 '13 at 12:00