> It is possible?
Yes. See:
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html#requestFocus()
- Oliver
> 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.
> 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.