开发者

Java start process in background only

Right now I have a frame in full screen exclusive mode, which commands the whole screen. The panel has a button which launches the windows native calculator program (just for testing purposes). Is it possible to have that process start completely in the background? Right now I have this:

    this.parent.setAlwaysOnTop(true);
    try {
    Process p = Runtime.getRuntime().exec("calc");
    } catch (IOException e1) {
    ErrorDialog error = new ErrorDialog("Error handling your shell acti开发者_开发知识库on");
    e1.printStackTrace();
    System.exit(0);
    }
    this.parent.setAlwaysOnTop(false);

This DOES do what I need, but doesn't make it pretty. It "minimizes" my window first, then starts calc, then re-maximizes my window. It all happens quickly but stuff is flashing all over the place. Is it possible to make "calc" run in the background without touching my main window and making it completely seamless?


This is in principle a window manager specific thing, at least on X systems (like Linux and most other Unixes with a GUI).

Some window managers start new programs always in the background, always in the foreground, or even require the user to draw the window's area with the mouse. Others respect the wishes of the program being started.

Thus, you could have a look at the command line options of the program you are starting, maybe they have an option like "start minimized" or similar.

If you are using KDE (and the KDE window manager), you can use kstart --onbottom ... or kstart --minimize ... to start your program, which will put the window on the bottom of the stack, or start it minimized. (Have a look at the kstart options, you'll also want to use --window or --windowclass to indicate the window.)


Test it out in Linux, maybe it doesn't flicker there. If not many people will use it in Windows, flickering shouldn't be a big concern.

I don't think there's a Java-specific way to handle this, you're launching an external process. How it launches is up to the OS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜