How to make JDialog not always on top of the parent

I have a JFrame that spawns two JDialogs. Each of the three windows must be configured (and, as I already wrote at the moment), but the JFrame will not go through the dialogs. When you click on any dialog, they will pop up one above the other (as one would expect), but the JFrame simply refuses to go to the front.

I need them to remain JDialogs (unlike JFrames themselves), since most of the current behavior is desirable (i.e. when another window / application blocks any or all windows, if you select any of the windows, they will all come to the front (whereas three JFrames will cause only the selected one to move forward)).

My JDialogs constructors have this effect:

SubDialog(JFrame parent /*, a handful, ofOther arguments */){
    super(parent, ModalityType.MODELESS); //not even the modeless helped
    setAlwaysOnTop(false); //not even the not always on top helped
    setUndecorated(true); //maybe this has something to do with it (unlikely, just fyi)?

    //some simple variable assignments

}

I even tried tossing setAlwaysOnTop(true)in my JFrame. No dice. I was getting desperation and even tried one of these numbers:

MyJFrame(String title){
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    addWindowFocusListener(new WindowAdapter(){
        public void windowGainedFocus(WindowEvent e){
            final Window w = e.getWindow();

            //PLEASE come to the front
            w.toFront();

            //even MOAR desperation
            SwingUtilities.invokeLater(new Runnable(){
                public void run(){
                    w.toFront(); //STILL no dice.
                }
            });
        }
    });
}

Thoughts? I said nothing.

+4
source share
2 answers

How to make JDialog not always on top of the parent

As stated in this Q & A: setModal task with 2 Jdialogs in a Jframe :

, . , , , toFront(), , , , . , toBack(). . Javadocs.

, Windows 7 , ( ) . , , .

+4

, . :

    JFrame frame = new JFrame();
    frame.setBounds(0,0,400,200);
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

// Special attention to this line, do not use same JFrame, create a dummy JFrame
// If you want to save memory you can also use new JDialog((JFrame)null)
    JDialog jd = new JDialog(new JFrame());
    jd.setModalityType(Dialog.ModalityType.MODELESS);
    jd.setBounds(0,0,100, 100);
    jd.setVisible(true);
0

Source: https://habr.com/ru/post/1530669/


All Articles