Solved

Bring Java application to front

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Updating Java 9 87
array11 challenge 16 52
wordcount challenge 11 78
Java passing arguments (type error) 2 35
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now