Java 仅在后台启动进程
现在我有一个处于全屏独占模式的框架,它控制整个屏幕。该面板有一个按钮,可启动 Windows 本机计算器程序(仅用于测试目的)。是否可以让该过程完全在后台启动?现在我有这个:
this.parent.setAlwaysOnTop(true);
try {
Process p = Runtime.getRuntime().exec("calc");
} catch (IOException e1) {
ErrorDialog error = new ErrorDialog("Error handling your shell action");
e1.printStackTrace();
System.exit(0);
}
this.parent.setAlwaysOnTop(false);
这确实满足了我的需要,但并没有使它变得漂亮。它首先“最小化”我的窗口,然后开始计算,然后重新最大化我的窗口。这一切都发生得很快,但到处都是闪烁的东西。是否可以使“calc”在后台运行而无需触摸我的主窗口并使其完全无缝?
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 action");
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原则上,这是窗口管理器特有的事情,至少在 X 系统上(如 Linux 和大多数其他带有 GUI 的 Unix)。
一些窗口管理器总是在后台启动新程序,总是在前台启动,甚至要求用户用鼠标绘制窗口区域。其他人则尊重正在启动的计划的意愿。
因此,您可以查看您正在启动的程序的命令行选项,也许它们有一个类似“启动最小化”或类似的选项。
如果您使用 KDE(和 KDE 窗口管理器),您可以使用
kstart --onbottom ...
或kstart --minimize ...
来启动您的程序,这会将窗口放在堆栈的底部,或者将其最小化。 (看看 kstart 选项,您还需要使用--window
或--windowclass
来指示窗口。)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 ...
orkstart --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.)在Linux下测试一下,也许不会闪烁。如果没有多少人会在 Windows 中使用它,那么闪烁应该不是一个大问题。
我认为没有特定于 Java 的方法来处理这个问题,您正在启动一个外部进程。它如何启动取决于操作系统。
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.