Solved

Bring Java application to front

Posted on 2007-11-22
5
6,355 Views
Last Modified: 2013-12-29
I would like to bring Java application (JFrame) on top of all other windows.

So far I found a partial solution. I was hoping that java 1.6 has a better one. This is the solution I have now:

1. I call the deiconify(frame) method.
2. Since this method will only bring the application on top if it is currently iconified (if the application is simply behind another window, nothing happens), I call the iconify() method first.

This results in the application being first iconified (if it is not already) and then deiconified. I would like to lose the first step.

Anyone knows how to achieve that?


public static void deiconify(Frame frame) {
        int state = frame.getExtendedState();
        state &= ~Frame.ICONIFIED;
        frame.setExtendedState(state);
    }
 
    public static void iconify(Frame frame) {
        int state = frame.getExtendedState();
        state |= Frame.ICONIFIED;
        frame.setExtendedState(state);
    }

Open in new window

0
Comment
Question by:Dejan Pažin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Assisted Solution

by:jcoombes
jcoombes earned 200 total points
ID: 20333653
Have you tried calling either of:

frame.toFront();

or

frame.setAlwaysOnTop(true)

I don't think that the second option does quite what you want, but might help you out....

Cheers


JC
0
 
LVL 17

Author Comment

by:Dejan Pažin
ID: 20333721
Yes, I tried it. The result is:

1. toFront only brings a frame on top of other frames inside VM, not on top of all open windows on the system. (from the javadoc of toFront method: "Places this Window at the top of the stacking order and shows it in front of any other Windows in this VM").

2. setAlwaysOnTop makes the application be always on top of all open windows on the system (like task manager). I dont want that, I just want to bring it on top when I need it.

Any other ideas?
0
 
LVL 2

Accepted Solution

by:
Beta07 earned 300 total points
ID: 20335371
frame.setAlwaysOnTop(true);
frame.setAlwaysOnTop(false);

Is a dirty solution.
0
 
LVL 17

Author Comment

by:Dejan Pažin
ID: 20337713

Beta07,

thats exactly what I did, and I agree its a dirty solution. But seems to work, so its a solution :)
0
 
LVL 1

Expert Comment

by:maartennieber
ID: 24200657
it appears

frame.setAlwaysOnTop(true);
frame.setAlwaysOnTop(false);

does not work in Linux (Hardy, JDK6). The call to frame.setAlwaysOnTop(false) moves the frame to the background again.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question