0

How to run an application(process) in java as background process.It should run back to my application my application shopuld be always on foreground.I am using

p = Runtime.getRuntime().exec( "C:/Program Files/Vehicle Spy 3/vspy3Demo.exe");

I have also used "/c" like the following:

p = Runtime.getRuntime().exec( "C:/Program Files/Vehicle Spy 3/vspy3Demo.exe /c");

But it is every time opening in foreground any one can help me..

hari
  • 43
  • 2
  • 7
  • 2
    java only starts the external application. It has no control whatsoever on what the app does later on.. – TheLostMind Jul 28 '14 at 10:47
  • If you are running a Swing Application then you might try [Window#setAlwaysOnTop](http://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#setAlwaysOnTop(boolean)). That way your application might cover other application you are running. – Sanjeev Jul 28 '14 at 10:52

1 Answers1

0

Depending on the widget toolkit you're using (swing, swt etc), I would suggest setting a timeout (e.g. 1 second) and then bring your java app window on top again.

Example with swt

shell.getDisplay().asyncExec(new Runnable() {
  public void run() {
    shell.forceActive(); // assuming shell is your java app main window
}

Example with Swing:

java.awt.EventQueue.invokeLater(new Runnable() {
    @Override
    public void run() {
        myFrame.toFront(); // assuming myFrame is your java app main window
        myFrame.repaint();
    }
});
Community
  • 1
  • 1
lviggiani
  • 5,824
  • 12
  • 56
  • 89