switch to java app...

Is there any way to bring a java app to the focus of the operating system? Suppose my user is running several applications in addition to my java app.. is there any way to bring the java app to the foreground when a particular event occurs?
[247 byte] By [bjb39a] at [2007-11-27 5:31:45]
# 1

You could try something like what I did in the following actionPerfomed method.

If you read the API, setAlwaysOnTop is not honored on all platforms.

Or by my girlfriend, but that's another story...

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class RevealExample implements Runnable, ActionListener {

private JFrame f;

private Timer timer;

public void run() {

f = new JFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setSize(500,400);

f.setLocationRelativeTo(null);

f.setVisible(true);

timer = new Timer(5000, this);

timer.start();

}

public void actionPerformed(ActionEvent evt) {

if ((Frame.ICONIFIED | f.getExtendedState()) != 0)

f.setExtendedState(Frame.NORMAL);

f.setAlwaysOnTop(true);

f.setAlwaysOnTop(false);

timer.stop();

}

public static void main(String[] args) {

EventQueue.invokeLater(new RevealExample());

}

}

Hippolytea at 2007-7-12 14:57:17 > top of Java-index,Java Essentials,Java Programming...
# 2
This doesn't seem to work for me. Any other thoughts?
bjb39a at 2007-7-12 14:57:17 > top of Java-index,Java Essentials,Java Programming...
# 3
What's yer platform, cowboy?
Hippolytea at 2007-7-12 14:57:17 > top of Java-index,Java Essentials,Java Programming...
# 4
Application will be deployed on both Windows XP SP2 Pro and SPARC Solaris
bjb39a at 2007-7-12 14:57:17 > top of Java-index,Java Essentials,Java Programming...
# 5
> This doesn't seem to work for me. Any other thoughts?Works fine for me, do you understand the code and how to test it? I ran it in Eclipse and then clicked on Eclipse so the Frame went to the background and a few seconds later it re-appeared.
_helloWorld_a at 2007-7-12 14:57:17 > top of Java-index,Java Essentials,Java Programming...
# 6
I just ran that on XP and it worked for me. Are you saying it fails on Solaris?
Hippolytea at 2007-7-12 14:57:17 > top of Java-index,Java Essentials,Java Programming...
# 7
No.. it failed on XP. Maybe it has something to do with the fact that the method is being called from [url= http://en.wikipedia.org/wiki/XML-RPC]XML-RPC?[/url] Does anyone have experience with this?
bjb39a at 2007-7-12 14:57:17 > top of Java-index,Java Essentials,Java Programming...
# 8
Maybe my method needs to also have a f.setVisible(true); just for good measure.
Hippolytea at 2007-7-12 14:57:17 > top of Java-index,Java Essentials,Java Programming...
# 9

Hmm, it seems as though this is definitely related to XML-RPC... I'm running a Java XML-RPC server thread which recieves a method call from a PHP XML-RPC client. Basically, the method call needs to change some data and bring the Java application to the foreground of the visible windows in the operating system. However, it seems that the method just dies, and doesn't do anything whenever I attempt to play around with any kind of JFrame display settings. Very strange.. has anyone come across this before?

bjb39a at 2007-7-12 14:57:17 > top of Java-index,Java Essentials,Java Programming...