Capturing escape key while JTable has focus

N

nomail_please

I have a JTable that's been used to display data only, with no cell
editing enabled. I need to capture the escape key to bind it to an
action (e.g., close dialog) but can't get it when the JTable has focus.
Keep in mind that the escape key is used by JTable to cancel editing
when in edit mode. I'm having a terrible time trying to undo that
default behavior.

Any ideas?

Thanks.
 
R

Robert Olofsson

(e-mail address removed) ([email protected]) wrote:
: I have a JTable that's been used to display data only, with no cell
: editing enabled. I need to capture the escape key to bind it to an
: action (e.g., close dialog) but can't get it when the JTable has focus.

Something like this perhaps?

// override ESCAPE to let it be used for closing the dialog...
table.getInputMap (JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
put (KeyStroke.getKeyStroke (KeyEvent.VK_ESCAPE, 0), "none");

/robo
 
N

nomail_please

Yes Sir! That did it.

Thank you.

This is what I had before:
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.remove(KeyStroke.getKeyStroke(KeyEvent.VK_CANCEL, 0));
I'm still at a loss as to why it doesn't work! Regardless, your tip is
perfect, and thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top