0

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();}
    }
jan_kiran
  • 301
  • 3
  • 16
  • This is not kiosk application, this is normal user machine, I want to make sure when my application prompts then user should give input and he should not escape – jan_kiran May 30 '18 at 15:51
  • What you really need then is precisely the kiosk mode, where the computer becomes a dumb device that only runs a specific program and nothing else. Any normal desktop is **designed** to be multitasking, and stealing the focus is a difficult thing. Not to mention that you can always use ctrl+alt+del to kill your program. I think full screen plus always on top is the best you can do without OS cooperation. – Alejandro May 31 '18 at 14:59

0 Answers0