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 / September 2005

Tip: Looking for answers? Try searching our database.

Focus

Thread view: 
Frances - 26 Sep 2005 22:01 GMT
I see two methods for setting focus:

-- requestFocus()
      Requests that this Component gets the input focus.

-- grabFocus()
   Requests that this Component get the input focus, and that this
Component's top-level ancestor become the focused Window.

   (which one is it, then, 'this Component' or 'top-level ancestor'? --
which one gets focus?  ('ancestor' meaning what exactly?  what if if you
have just one component (and thus no 'ancestor'...))

neither one of these two methods is working for me.. let's say I have a
JTextArea called TA...  neither TA.grabFocus() or TA.requestFocus() is
working..

why no simple Focus() method?  (focus this component...  seems too
simple, I know...)  thank you very much...  Frances
Frances - 26 Sep 2005 22:15 GMT
> I see two methods for setting focus:
>
[quoted text clipped - 15 lines]
> why no simple Focus() method?  (focus this component...  seems too
> simple, I know...)  thank you very much...  Frances

sorry, neglected to mention, this is not in reponse to user-event, but
for when window opens, it's for an IM window, so top textArea should
NEVER have focus and bottom textArea should ALWAYS have focus..  thanks
again...
Vova Reznik - 26 Sep 2005 22:27 GMT
> sorry, neglected to mention, this is not in reponse to user-event, but
> for when window opens, it's for an IM window, so top textArea should
> NEVER have focus and bottom textArea should ALWAYS have focus..  thanks
> again...

Make research:
add focus listener to both areas
and print out something short when area gained focus.
Roedy Green - 26 Sep 2005 23:25 GMT
>sorry, neglected to mention, this is not in reponse to user-event, but
>for when window opens, it's for an IM window, so top textArea should
>NEVER have focus and bottom textArea should ALWAYS have focus..  thanks
>again...

try calling such methods in your addNotify method rather than the
constructor.  See http://mindprod.com/jgloss/addnotify.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Frances Del Rio - 27 Sep 2005 17:40 GMT
>>sorry, neglected to mention, this is not in reponse to user-event, but
>>for when window opens, it's for an IM window, so top textArea should
[quoted text clipped - 3 lines]
> try calling such methods in your addNotify method rather than the
> constructor.  See http://mindprod.com/jgloss/addnotify.html

thank you Roedy, and everyone else for their responses..  in the end
used setFocusable(boolean) method..  (yes, need to figure out the thread
issue w/swing...  yikes....  I find it very complicated..  what to call
from threads, what not to..)
thanks again..
Roedy Green - 27 Sep 2005 19:56 GMT
> I find it very complicated..  what to call
>from threads, what not to..)

Keep in mind that just because it works once does not mean it will
always work. Unless you have an explicit comment about thread safety,
use the invokeLater gambit to invoke from the non Swing thread.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Oliver Wong - 26 Sep 2005 22:17 GMT
>I see two methods for setting focus:
>
[quoted text clipped - 15 lines]
> why no simple Focus() method?  (focus this component...  seems too simple,
> I know...)  thank you very much...  Frances

   Based on these descriptions, it sounds like grabFocus() is the one you
want. Notice that if you have a textbox in a window, and that window is not
the active window, then not only should the input focus be set on the
textbox, but also the window containing that textbox should be brought to
the front of the screen and become active.

   The "ancestor" term comes from the fact that in Swing, the widgets form
a tree, with a parent component containing all of its children component.
Depending on the exact terminology used, if you have only one component,
that component is its own ancestor.

   - Oliver
Roedy Green - 26 Sep 2005 22:36 GMT
>       Requests that this Component gets the input focus.
>
[quoted text clipped - 5 lines]
>which one gets focus?  ('ancestor' meaning what exactly?  what if if you
>have just one component (and thus no 'ancestor'...))

With grab, the window is the focused WINDOW. It become the Active
Window.  In Windows, it gets a different colour title bar.  Then
within the window the particular component has focus.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



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.