I have the below code which will make the window to show always on top until the users closes, Even I have implemented focus listener and when the focus is I am setting to always top and focus is gained back, this works perfect in windows. In mac and linux user can switch to different desktop/screen, is there a way to replicate the window and if the user closes in one place if closes everything (basically to be in sync). This is not kiosk application, application runs is normal user machine, I want to make sure when my application prompts then user should give input and he should not escape
import java.awt.event.*;
import javax.swing.*;
public class MainWindow extends JFrame implements WindowFocusListener
{
public MainWindow()
{
addWindowFocusListener(this);
setAlwaysOnTop(true);
this.setFocusable(true);
// this.setFocusableWindowState(true);
panel = new JPanel();
//setSize(WIDTH,HEIGHT);
setUndecorated(true);
setLocation(X,Y);
setExtendedState(MAXIMIZED_BOTH);
setVisible(true);
}
public void windowGainedFocus(WindowEvent e){}
public void windowLostFocus(WindowEvent e)
{
if(e.getNewState()!=e.WINDOW_CLOSED){
//toFront();
//requestFocus();
setAlwaysOnTop(false);
setAlwaysOnTop(true);
//requestFocusInWindow();
System.out.println("focus lost");
}
}
private JPanel panel;
private static final int WIDTH = 200;
private static final int HEIGHT = 200;
private static final int X = 100;
private static final int Y = 100;
public static void main(String args[]){
new MainWindow();}
}