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
posted
0
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
posted
0
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
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
posted
0
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