Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2008

Tip: Looking for answers? Try searching our database.

Input/action map prob on JTextComponent

Thread view: 
Karsten Wutzke - 21 Mar 2008 01:11 GMT
Hello,

I use the following code to assign key strokes to actions to be
performed:

Action act = new ... (whatever)
JTextComponent tc = new ... (some standard text component)

Object key = action.getValue(Action.NAME);
   
tc.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0), key);    <--- not working!
tc.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
KeyEvent.CTRL_DOWN_MASK), key);
tc.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("alt
S"), key);

tc.getActionMap().put(key, caSend);

There's nothing basically wrong with the above code. When entering
something into the text component, the action atop is performed on Alt-
S or Ctrl-ENTER, however it is *NOT* performed when not using a
modifier. Might have to with the component being a text component. ->?

Why doesn't it work?

How do I make it work?

That text component is supposed to be single lined, but resizability
simply looks better with the app...

I've just tried using a JTextField instead and the RETURN only
keystroke *works*. Does anyone know why the former styled text pane/s
don't?

Karsten
Karsten Wutzke - 21 Mar 2008 03:07 GMT
> Hello,
>
[quoted text clipped - 32 lines]
>
> Karsten

Oops... the line

tc.getActionMap().put(key, caSend);

was supposed to be

tc.getActionMap().put(key, act);

Anyway the code is right and tested, since both other keystrokes
work...

Karsten


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.