Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Capturing escape key while JTable has focus

Reply
Thread Tools

Capturing escape key while JTable has focus

 
 
nomail_please@thank.you
Guest
Posts: n/a
 
      10-10-2003
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.

 
Reply With Quote
 
 
 
 
Robert Olofsson
Guest
Posts: n/a
 
      10-10-2003
() 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
 
Reply With Quote
 
 
 
 
nomail_please@thank.you
Guest
Posts: n/a
 
      10-10-2003
Yes Sir! That did it.

Thank you.

This is what I had before:
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCU SED_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.

Robert Olofsson wrote:
> () 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read strings cantaining escape character from a file and useit as escape sequences? slomo Python 5 12-02-2007 11:39 AM
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
how to find that escape key is pressed while taking the string sudhir C Programming 16 12-05-2005 05:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57