Have you looked into InputMap or KeyMap? They allow you to map a KeyStroke
(like ENTER) to a custom action. They typically work better than
KeyListeners, which (if I remember correctly) are fired too late, that is,
after the key stroke has already been processed. The only potential problem
with InputMap or KeyMap is that the JTable already maps the ENTER keystroke
to a particular action. Overriding an already defined keystroke can be
tricky. Maybe someone else on this mailing list can help.

If all else fails, the brute force approach will probably work. I've had
success overriding this method in order to trap, process or redirect
keystrokes:

   protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
             int condition, boolean pressed)

I've overriden this in a subclass of JTextArea, but I suspect you could also
use it in a subclass of JTable.

Hope that helps,

pf

-----Original Message-----
From: Alex Kravets
To: [EMAIL PROTECTED]
Sent: 1/2/02 3:50 PM
Subject: Making ENTER behave as TAB in JTable

Hi,

I need to make "ENTER" behave as "TAB" in my JTable, I read some 
articles about this, but nobody has a real solution for this. I know how

to achieve this with JTextField and such, but how do I implement this 
for JTable?
Here is the code:
===============================
addKeyListener(new KeyAdapter() {
   public void keyPressed(KeyEvent evt) {
             int key = evt.getKeyCode();
             if (key == KeyEvent.VK_ENTER)
                 transferFocus();}});
===============================

thanks,
Alex Kravets

_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to