Reputation: 4601
I have made my java application as Single instance application. I have implemented File Lock system for the same.
If the application is already running, I want to show the running application to front. How do I achieve that? How can I acess the running process of that application and show it?
Upvotes: 2
Views: 1732
Reputation: 168845
JWS not only provides an x-plat SingleInstanceService
, but it also (from memory) pops the application toFront()
on newActivation(String[])
. Of course if it is not automatic, you can call it explicitly.
Here is a demo. of the SIS.
Upvotes: 1
Reputation: 21459
What you are asking for is OS dependent but you can always have your own implementation to do this. You application can listen on a certain port for a bring-to-front
command that you can send from the second instance of your application.
void main(String[] args){
if(applicationAlreadyRunning){
// Send bring-to-front message to running instance on a known port
// and exit.
}
}
When a bring-to-front message is received you can do:
public void BringToFrontCommandReceived(){
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
myMainFrame.toFront();
myMainFrame.repaint();
}
});
}
Upvotes: 1