Java JFrame Show showModalFrame(final JFrame newFrame, final JFrame owner)

Here you can find the source of showModalFrame(final JFrame newFrame, final JFrame owner)

Description

show Modal Frame

License

Open Source License

Declaration

public static void showModalFrame(final JFrame newFrame, final JFrame owner) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import javax.swing.JFrame;

public class Main {
    private static ArrayList<JFrame> reaktivationQue = new ArrayList<>();

    public static void showModalFrame(final JFrame newFrame, final JFrame owner) {
        addToQue(owner);/*from  w  w  w.  j  ava2 s . co m*/

        newFrame.setLocationRelativeTo(owner);
        owner.setVisible(false);
        owner.setEnabled(false);
        newFrame.setVisible(true);
        newFrame.toFront();

        Thread t = new Thread(new Runnable() {
            public void run() {
                while (newFrame.isVisible() || !isFirstInQue(owner)) {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                    }
                }

                owner.setVisible(true);
                owner.setEnabled(true);
                owner.toFront();
                removeFromQue(owner);
            }
        });
        t.start();
    }

    synchronized private static void addToQue(JFrame frame) {
        reaktivationQue.add(frame);
    }

    synchronized private static boolean isFirstInQue(JFrame frame) {
        return reaktivationQue.get(reaktivationQue.size() - 1) == frame;
    }

    synchronized private static void removeFromQue(JFrame frame) {
        reaktivationQue.remove(frame);
    }
}

Related

  1. showAndSaveReportFile(JFrame frmParent, File defaultReportFile, String data)
  2. showDemoFrame(JFrame frame)
  3. showFrame(JFrame frame)
  4. showFrame(JFrame frame, JFrame parent)
  5. showHelp(JFrame frame, String path)
  6. showOnScreen(int screen, JFrame frame)
  7. showSaveDialog(JFrame parent, String message)
  8. showSuccess(JFrame frame)
  9. showTextboxDialog(javax.swing.JFrame frame, String texto, String title, String valorInicial, int type)