• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disable Enter key in a JTable

 
marc bourdon
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell what to use to disable the enter key in a JTable? I switched over from JAVA 1.2.2 to JAVA 1.3.0 which I used the command "inventoryTable.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0))", which worked fine. But in JAVA 1.3.0, it is now obsolete. Any example would be helpful.
Thanks in advance,
Marc Bourdon
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could put a KeyListener on the JTable, and listen for a VK_ENTER KeyEvent, and when that happens you consume() it.
 
marc bourdon
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already have a KeyListener for the JTable, but the default for the enter key is to do a skip to the next line. Each time I press the enter key, it skips the line and selects the other line under the one I wanted to select.
Marc
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you consume() a KeyEvent it will do nothing.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a method is deprecated, the API will almost always give information on what other methods to use instead. Sure enough, the API for javax.swing.KeyStroke)" TARGET=_blank rel="nofollow">unregisterKeyboardAction() does indeed contain relevant info. Looks like you can use getActionMap() or getInputMap() to retrieve the existing bindings, and then use the associated remove() methods to remove the appropriate key bindings. I'm not particularly familiar with these methods myself, so I can't say much more right now - but hopefully this gives you an idea what to look into. Study the APIs for details. Good luck!
 
marc bourdon
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim, I did study the APIs for the InputMap to use the remove() but didn't get any success. But what I noticed when I press on the control key and press enter at the same time, it doesn't skip to the next line. Is there a way that I could assign the control key kinda pressed each time I press the enter in my JTable?
Marc
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic