How to set focus the already running application?

前端 未结 2 551
时光说笑
时光说笑 2021-01-15 19:35

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 \

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-15 20:07

    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();
    }
    

提交回复
热议问题