Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Disable Enter key in JTable  RSS feed

 
jack morton
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

How to disable Enter key when a cell is in editing mode ?

Best regards
 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jack morton wrote:Hi all,

How to disable Enter key when a cell is in editing mode ?

Best regards


Hi Jack,

Hope this sample will help...



Just put your action when "ENTER" key pressed into your event..

Best Regards,

Ramses
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this sample will help...


Using a KeyListener is not the approach to use. Please read the Swing tutorial on "How to Use Key Bindings" to understand how Swing works with KeyEvents. The example won't work. Focus is on the editor not the table.

How to disable Enter key when a cell is in editing mode


Well, as I suggested above, Swing uses Key Bindings to map KeyStrokes to an Action. In the case of an Enter key it is used to provide two pieces of functionality:

a) when editing a cell it is used to stop editing
b) when not editing a cell focus is transferred to the next row.

If you want to remove the functionality of the Enter key completely then you can just remove the Key Binding. Read the section from the Swing tutorial on How to Use Key Bindings for more information.

If you want to remove the editing functionality, but keep the non-editing functionality then you need to change the default Action. The easiest way to do this it to probably wrap the original Action and to ignore the Enter key when table.isCellEditing() returns true. To help you with this approach you might want to look at the way I customized the deault Tab Action in Table Tabbing.
 
jack morton
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
than you Ramses Butarbutar and Rob Camick for helping
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!