aspose file tools*
The moose likes Beginning Java and the fly likes Disable Enter key in a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Disable Enter key in a JTable" Watch "Disable Enter key in a JTable" New topic
Author

Disable Enter key in a JTable

marc bourdon
Greenhorn

Joined: May 29, 2001
Posts: 6
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

Joined: Sep 29, 2000
Posts: 8521
You could put a KeyListener on the JTable, and listen for a VK_ENTER KeyEvent, and when that happens you consume() it.


"JavaRanch, where the deer and the Certified play" - David O'Meara
marc bourdon
Greenhorn

Joined: May 29, 2001
Posts: 6
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

Joined: Sep 29, 2000
Posts: 8521
If you consume() a KeyEvent it will do nothing.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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!


"I'm not back." - Bill Harding, Twister
marc bourdon
Greenhorn

Joined: May 29, 2001
Posts: 6
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
 
subject: Disable Enter key in a JTable
 
Similar Threads
JTable size
Disable Enter key in a JTable
Replacing a line
JTable
Disable Enter key in JTable