• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Disable Enter key in JTable

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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

Best regards
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
than you Ramses Butarbutar and Rob Camick for helping
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic