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 2006

Tip: Looking for answers? Try searching our database.

how to force a window to stay in background

Thread view: 
giangiammy - 20 Sep 2006 16:13 GMT
hi all,

I want a message window, created as:

static void showWarning(JFrame frame, String s) {
       if (frame == null || s == null)
           return;
       Window window = SwingUtilities.getWindowAncestor(frame);
       JOptionPane.showMessageDialog(window, s);
   }

it have a message the user must acknowledge:
it block alla the button og main window until I press OK, as desired,
but if I click on the main window, the main window is brought
to foreground and hides the dialog.
How can I have a dialog always in foreground, until I press OK?

thanks
giammy
giangiammy - 20 Sep 2006 16:17 GMT
sorry for the original subject: i want a dialog window to
stay in FOREGROUND ...

> hi all,
>
[quoted text clipped - 15 lines]
> thanks
> giammy
Oliver Wong - 20 Sep 2006 19:13 GMT
> sorry for the original subject: i want a dialog window to
> stay in FOREGROUND ...

   Lookup "Modal dialog".

   - Oliver
Michael Rauscher - 20 Sep 2006 19:18 GMT
giangiammy schrieb:
> sorry for the original subject: i want a dialog window to
> stay in FOREGROUND ...

See java.awt.Window#setAlwaysOnTop. Haven't used it so far, so give it a
try.

Bye
Michael
Michael Rauscher - 20 Sep 2006 19:36 GMT
Michael Rauscher schrieb:
> giangiammy schrieb:
>> sorry for the original subject: i want a dialog window to
>> stay in FOREGROUND ...
>
> See java.awt.Window#setAlwaysOnTop. Haven't used it so far, so give it a
> try.

Forget it. I should have looked a bit deeper at your posting. Of course,
you want a modal dialog as Oliver stated already.

Bye
Michael
Larry Barowski - 20 Sep 2006 21:51 GMT
> hi all,
>
[quoted text clipped - 12 lines]
> to foreground and hides the dialog.
> How can I have a dialog always in foreground, until I press OK?

If "frame" is the main window, then use
JOptionPane.showMessageDialog(frame, s);
giangiammy - 21 Sep 2006 08:40 GMT
> If "frame" is the main window, then use
> JOptionPane.showMessageDialog(frame, s);

Yes, I tested, putting the main frame (calling it with this)
and it works correctly, but if I use it from an applet,
the "this" reppresent aan applet, not a frame:
I need to get the frame containig the applet - correct?
Now I search the function to get this info

giammy
Andrew Thompson - 21 Sep 2006 10:25 GMT
> > If "frame" is the main window, then use
> > JOptionPane.showMessageDialog(frame, s);
>
> Yes, I tested, putting the main frame (calling it with this)
> and it works correctly, but if I use it from an applet,
> the "this" reppresent aan applet, not a frame:

You are in luck.  Every applet has an associated frame.

Try this from within an applet.
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Frame.html#getFrames()>

Note that is is a static method, you do not need an
instance of frame to call it, and note particularly the
description (which mentions applets).

Andrew T.
Andrew Thompson - 21 Sep 2006 10:36 GMT
> > > If "frame" is the main window, then use
> > > JOptionPane.showMessageDialog(frame, s);
[quoted text clipped - 4 lines]
>
> You are in luck.  Every applet has an associated frame.

Crap!  I wish I had read Larry's word more carefully.

A JOptionPane can accept a 'null' frame.

You do not even need to attach it to the 'default'
frame and it should act as you specified.

Andrew t.
giangiammy - 21 Sep 2006 11:04 GMT
> You do not even need to attach it to the 'default'
> frame and it should act as you specified.

OK I got it: I need to pass the main frame or the
main applet to get the behaviour I want.
If I pass the null, the pop up is shown,
but it can be put in background.

giammy
Andrew Thompson - 21 Sep 2006 12:16 GMT
> > You do not even need to attach it to the 'default'
> > frame and it should act as you specified.
...
> OK I got it: I need to pass the main frame or the
> main applet to get the behaviour I want.

Ummm.. no.

The two ways on offer are..

Frame f = Frame.getFrames()[0];
JOptionPane.showMessageDialog(f, theMessage);

...or..

JOptionPane.showMessageDialog(null, theMessage);

(Note that neither accepts an applet as an argument.)

> If I pass the null, the pop up is shown,
> but it can be put in background.

Again, no. *All* instances of the JOptionPane (JOP) block
input to the original application (or applet) until dismissed.

The end user can 'alt tab' (or whatever) to other
applications or windows that are open, but if they
return to the web page that opened the JOP,
the JOP will appear 'above the web page' and block
input to the applet until dismissed.

Andrew T.
Babu Kalakrishnan - 21 Sep 2006 12:40 GMT
>>>You do not even need to attach it to the 'default'
>>>frame and it should act as you specified.
[quoted text clipped - 10 lines]
> Frame f = Frame.getFrames()[0];
> JOptionPane.showMessageDialog(f, theMessage);

Out of curiosity : What does SwingUtilities.getWindowAncestor(this)
return when invoked from an Applet ? If that does return the frame
that contains the Applet, it would probably be a better idea to
use it as the parent rather than Frame.getFrames()[0] (More
deterministic if getFrames() returns more than one Frame)

> ...or..
>
> JOptionPane.showMessageDialog(null, theMessage);
>
> (Note that neither accepts an applet as an argument.)

Hmm ? Isn't the first argument of the showMessageDialog method a
java.awt.Component ? In which case it should allow an Applet to
be passed as the parentComponent.

BK
Andrew Thompson - 21 Sep 2006 13:11 GMT
....
> > The two ways on offer are..
> >
> > Frame f = Frame.getFrames()[0];
> > JOptionPane.showMessageDialog(f, theMessage);
...
> > JOptionPane.showMessageDialog(null, theMessage);
> >
> > (Note that neither accepts an applet as an argument.)
...
> Hmm ? Isn't the first argument of the showMessageDialog method a
> java.awt.Component ?

LOL!  while typing that entire post, I was thinking..
'SOK*, Babu might notice this post and jump in with
accurate details.

* 'SOK translates to 'It is OK'.

...and on the bits I trimmed (shrugs vaguely) - dunno'.

Shall we leave it as 'an exercise for the OP'?    ;-)

Andrew T.
Babu Kalakrishnan - 21 Sep 2006 13:52 GMT
> ....
>
[quoted text clipped - 23 lines]
>
> Shall we leave it as 'an exercise for the OP'?    ;-)

Haha.. well I hadn't noticed it till I wrote the initial question - I
was really wondering if the SwingUtilities method wouldn't provide you
with the actual Frame that parented the Applet, because getFrames()[0]
seemed so arbitrary.

Anyway good to hear that I'm keeping someone on their toes ;-) Never
realized I had this reputation of "policing" the newsgroup !!

BK
giangiammy - 21 Sep 2006 14:33 GMT
> Out of curiosity : What does SwingUtilities.getWindowAncestor(this)
> return when invoked from an Applet ? If that does return the frame
> that contains the Applet, it would probably be a better idea to
> use it as the parent rather than Frame.getFrames()[0] (More
> deterministic if getFrames() returns more than one Frame)

I tested SwingUtilities.getWindowAncestor(this),
but it did not get me the correct
behavious of the pop up neither in the standalone application
nor in the applet.

> > ...or..
> >
[quoted text clipped - 5 lines]
> java.awt.Component ? In which case it should allow an Applet to
> be passed as the parentComponent.

Yes: I have done in this way: I pass the applet as parent

bye
giammy


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.