?
Solved

Bring Java application to front

Posted on 2007-11-22
5
Medium Priority
?
6,405 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 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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