Solved

Bring Java application to front

Posted on 2007-11-22
5
6,279 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 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

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

Suggested Solutions

Title # Comments Views Activity
print map entry 34 72
windows explorer path to command prompt 5 54
ejb on wildfly 5 30
sql import cannot be resolved jsp 3 45
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

840 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