Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foreground JFrame problem (Java 1.5.0)

Status
Not open for further replies.

themanfalconar

Technical User
Sep 13, 2003
10
0
0
EU
Hi there,

I've created a network instant message client/server, similar to MSN. This problem relates to the client only. In simple terms the client is an extension of a JFrame with various text fields and buttons.

I have implemented a notifier facility that pops up a separate undecorated JFrame (with the message) in the system tray area (assuming Windoze) when a message has been received. This works fine, but it is unnecessary when the actual chat window is the active window. Therefore I have used WindowListeners and WindowFocusListeners to detect whether the chat window is active; when it isn't active, then the notifier pops up.

The problem is that when the chat window is not the foreground window, or is iconified, the notifier window also pops up in the background. Unless you have no other windows open, you can't see the notifier. It seems that the notifier works at the same foreground level as the chat window. This is no good, as it defeats the point!!!

Do any of you know how to force a JFrame to become the foreground window, particularly if the code that invokes it comes from a JFrame that is NOT the foreground window?

The basic skeleton of the code is:
Code:
public class ChatWindow extends JFrame
.
.
.
// Thread that is continually listening for messages

if(messageDetected)
{
    // NotifierWindow is simply a JFrame that is undecorated
    NotifierWindow notify = new NotifierWindow(message);   
}
else
{
    // keep waiting for messages
}

// end of thread loop
.
.
.

Obviously the code is much more complex than illustrated above, but that's basically how it works.

Please help!!!

Cheers,

Dan
 
You can try

notify.toFront();

This will not bring the window to the foreground if other non-java windows are open, but it will at least make it the foreground java window.

Also, if the chat window is iconified, try

notify.setExtendedState( Frame.MAXIMIZED_BOTH );

This will un-iconify the notify window and leave the chat window iconified.

Perhaps a combination of both will at least improve things. I don't know of any way to get java windows in front of non-java windows.
 
Thanks for your reply. Unfortunately neither tactic really solves the problem.

The notify.toFront() doesn't make any difference anyway as the two JFrames do not overlap generally.

Thanks anyway,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top