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 / General / January 2006

Tip: Looking for answers? Try searching our database.

Set the focus to a Frame

Thread view: 
Marco - 16 Jan 2006 20:55 GMT
It is possible?
Oliver Wong - 16 Jan 2006 21:31 GMT
> It is possible?

   Yes. See:

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html#requestFocus()

   - Oliver
Luc The Perverse - 16 Jan 2006 21:53 GMT
> It is possible?

Please don't post your question in the subject line.

Have you tried searching google for Java frame focus?  Or just for JFrame
documentation?

Take a look at the documentation here
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFrame.html

Notice the setFocusable function.  You need this functionality to add key
handlers to the frame - so it can be useful to know.

--
LTP

:)
Marco - 16 Jan 2006 22:08 GMT
> Have you tried searching google for Java frame focus?  Or just for JFrame
> documentation?
[quoted text clipped - 4 lines]
> Notice the setFocusable function.  You need this functionality to add key
> handlers to the frame - so it can be useful to know.

I need it for java.awt.Frame, not for javax.swing.JFrame.

I search, and try any method [Frame.toFront()], but they don't work on my
Applet. I now think that my problem is not how do the focus to Frame
(setVisible(true) always do this), but a second Applet (without Frame) in
the same html page, that give the focus to itself, sending the Frame in the
back.

Excuse for my English.

Marco
Luke Webber - 16 Jan 2006 23:05 GMT
>> Have you tried searching google for Java frame focus?  Or just for JFrame
>> documentation?
[quoted text clipped - 14 lines]
>
> Excuse for my English.

requestFocus() will work for java.awt.Frame as well. It's inherited from
java.awt.Component.

Luke
Marco - 17 Jan 2006 12:29 GMT
> requestFocus() will work for java.awt.Frame as well.

Thank tou, I try this, but it don't works, because, as I understand,
Frame.setvisible(true) already give focus to my Frame; but another Applet
(without Frame) give, after this, to "parente" html page the focus (only in
Java SUN 1.5, because with Microsoft 1.1.4 the focus remain to the Frame).

I think that my problem it isn't how give the focus to my frame from first
Applet, but how remove focus from html page when the second Applet (that
have his paint method, but not a own Frame) ends.

N.B. Second Applet must be the second, and cannot be the first.
Marco - 19 Jan 2006 09:23 GMT
> It is possible?

I have, in a html page, 3 applet: only the second open a Frame, while the
fist write, with paint method, on html page and the third tell to the first
one when the second is completely loaded.

The problem is that the first applet (or the third too, I don't know),
remove the focus from Frame, and send it to html page.

How can I remove the focus from a Component in html page?

I try this with Frame frame:

1)
frame.setVisible(true);
frame.requestFocus();

This don't work, because frame.setVisible(true); already give the focus to
Frame of second applet, but paint of the first one resends it immediatly to
html page.

2)
   frame.setVisible(true);
   frame.addFocusListener(new FocusListener()
    {
     public void focusGained(FocusEvent e)
      {frame.requestFocus();}
     public void focusLost(FocusEvent e)
      {frame.requestFocus();}
    });

This don't work, because focusLost see only lost of focus by keyboard, but
in this case is the fist applet that alone gain the focus for html page.

3) In html page, with javascript, I insert:

<BODY onFocus="this.windows.blur()" ecc.

This don't work, and I don't know the cause.

4) I set the name for Frame with this.setName("myframe"); in the constructor
of it, but I don't know if I can use this for sameting as
"myframe.setFocus()" in any language (java, or javascript in partent html).

Do you have any solution?

Thank you

Marco

Marco - 19 Jan 2006 10:44 GMT
> This don't work, because focusLost see only lost of focus by keyboard, but
> in this case is the fist applet that alone gain the focus for html page.

Excuse me, I all wrong in my precedent message, because I don't have
understand what means "lost of focus by keyboard". Now, I understand and
resolved as the following:

   frame.setVisible(true);

   if (!accessoutente)
    {
     myfirstbutton.requestFocus();
     myfirstbutton.addFocusListener(new FocusListener()
      {
       public void focusGained(FocusEvent e)
        {}
       public void focusLost(FocusEvent e)
        {
         if (!accessoutente)  {myfirstbutton.requestFocus();}
         else {myfirstbutton.removeFocusListener(this);}
        }
      });
    }

...where accessoutente is a boolean, that the constructor set to false, and
all listeners (bottuns, keyboard) set to true.


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.