?
Solved

Bring Java application to front

Posted on 2007-11-22
5
Medium Priority
?
6,514 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
5 Comments
 
LVL 4

Assisted Solution

by:jcoombes
jcoombes earned 800 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 1200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

862 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