Forums Register Login

Disable Enter key in a JTable

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
You could put a KeyListener on the JTable, and listen for a VK_ENTER KeyEvent, and when that happens you consume() it.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
If you consume() a KeyEvent it will do nothing.
+Pie Number of slices to send: Send
When a method is deprecated, the API will almost always give information on what other methods to use instead. Sure enough, the API for 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!
+Pie Number of slices to send: Send
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
Run away! Run away! Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1738 times.
Similar Threads
Disable Enter key in JTable
Replacing a line
Disable Enter key in a JTable
JTable
JTable size
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:10:21.