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 / December 2003

Tip: Looking for answers? Try searching our database.

Change focus with TAB key in JTextArea

Thread view: 
John Moore - 15 Dec 2003 14:56 GMT
In my JTextAreas, I want the TAB key to behave as it does with
JTextFields, i.e., change the focus to the next component, and not
enter a tab into the text. I've done a thorough Googling and every
solution I've found fails to work in Sun's JDK 1.4.2 on Linux. What's
the current favoured method of doing this?

John
Adam - 15 Dec 2003 15:13 GMT
> In my JTextAreas, I want the TAB key to behave as it does with
> JTextFields, i.e., change the focus to the next component, and not
> enter a tab into the text. I've done a thorough Googling and every
> solution I've found fails to work in Sun's JDK 1.4.2 on Linux. What's
> the current favoured method of doing this?
I don't know.
Maybe you should subclass JTextArea, override processKeyEvent
and transferFocus() if keyEvent is VK_TAB
otherwise call super.processKeyEvent ?

Adam
John Moore - 15 Dec 2003 18:27 GMT
>Maybe you should subclass JTextArea, override processKeyEvent
>and transferFocus() if keyEvent is VK_TAB
>otherwise call super.processKeyEvent ?

This works pretty well, it seems. Thanks!

John
Andrew Thompson - 15 Dec 2003 15:45 GMT
> In my JTextAreas, I want the TAB key to behave as it does with
> JTextFields, i.e., change the focus to the next component, and not
> enter a tab into the text. I've done a thorough Googling and every
> solution I've found fails to work in Sun's JDK 1.4.2 on Linux. What's
> the current favoured method of doing this?

ctrl^tab ..in both Windows and Metal L&F's

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Andrew Thompson - 15 Dec 2003 15:47 GMT
> > In my JTextAreas, I want the TAB key to behave as it does with
....
> > .....fails to work in Sun's JDK 1.4.2 on Linux. What's
> > the current favoured method of doing this?
>
> ctrl^tab ..in both Windows and Metal L&F's

Sorry, of course that is windows, when you
are using Linux!  (shrugs) Give it a try..
John Moore - 15 Dec 2003 18:17 GMT
>> ctrl^tab ..in both Windows and Metal L&F's
>
>Sorry, of course that is windows, when you
>are using Linux!  (shrugs) Give it a try..

Well, actually what I want is to get Tab to behave the same as for
other fields, rather than what to use instead. It beats me why this is
so tricky, and why the solution for 1.3 broke in 1.4.

John
Alan Moore - 15 Dec 2003 20:40 GMT
>In my JTextAreas, I want the TAB key to behave as it does with
>JTextFields, i.e., change the focus to the next component, and not
[quoted text clipped - 3 lines]
>
>John

Keyboard focus traversal underwent a major change in v1.4.0, as
described in this article:

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/FocusSpec.html

To get TAB (and Shift-TAB) to function as focus traversal keys, you
have to use the setFocusTraversalKeys(int, java.util.Set) method of
java.awt.Container.


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



©2009 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.