如何设置已经运行的应用程序的焦点? [英] How to set focus the already running application?

查看:212
本文介绍了如何设置已经运行的应用程序的焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个ServerSocket端口来运行我的Java Swing应用程序的一个实例,所以如果用户试图打开另一个程序实例,我会向他显示一个警告:另一个实例已经打开。这工作正常,但没有显示此消息,我想设置专注于正在运行的应用程序本身,就像一些程序(MSN Messenger),即使它被最小化。

I am using a ServerSocket port to run one instance only of my Java Swing application, so if a user tries to open another instance of the program, i show him a warning that "Another instance is already open". This works fine, but instead of showing this message i want to set focus on the running application itself, like some programs does (MSN Messenger), even if it was minimized.

有没有解决这个各种操作系统?

Is there a solution for this for various operating systems ?

推荐答案

因为你使用服务器套接字我假设你使用java .net.BindException来检测你的应用程序已经在运行。如果你开始第二个实例,你可以发送一个控制消息,告诉你第一个应用程序在退出之前正常化(如果最小化)。

Since you use a server socket I assume that you use the java.net.BindException to detect that you application is already running. If you start a second instance you could send a control message which instructs you first app to normalize (if minimized) before exiting.

if (msg == BRING_TO_FRONT ) {
   frame.setState(Frame.NORMAL);
   frame.toFront();
}

这篇关于如何设置已经运行的应用程序的焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆