Java JFrame Parent execLoop(JComponent editor, Frame parent, boolean modal, int w, int h)

Here you can find the source of execLoop(JComponent editor, Frame parent, boolean modal, int w, int h)

Description

exec Loop

License

Open Source License

Declaration

public static void execLoop(JComponent editor, Frame parent, boolean modal, int w, int h) 

Method Source Code

//package com.java2s;
/**/*  w w w. j a v a  2s .com*/
 * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Eclipse Public License (EPL).
 * Please see the license.txt included with this distribution for details.
 * Any modifications to this file must keep this entire header intact.
 */

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;

import java.awt.Toolkit;
import java.awt.Window;

import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;

import javax.swing.JScrollPane;

public class Main {
    public static void execLoop(JComponent editor, Frame parent, boolean modal) {
        execLoop(editor, parent, modal, 800, 600);
    }

    public static void execLoop(JComponent editor, Frame parent, boolean modal, int w, int h) {
        JDialog dialog = new JDialog(parent, modal);

        Container contentPane = dialog.getContentPane();
        contentPane.setLayout(new BorderLayout());

        JScrollPane scrollPane = new JScrollPane(editor);
        contentPane.add(scrollPane, BorderLayout.CENTER);

        dialog.setSize(w, h);
        centerWindow(dialog);
        dialog.setVisible(true);

    }

    public static void execLoop(JComponent editor, boolean modal) {
        execLoop(editor, new JFrame(), modal);
    }

    /**
     * Addes the given editor to a jframe and halts until it is closed)
     */
    public static void execLoop(JComponent editor) {
        execLoop(editor, true);

    }

    public static void centerWindow(Window component) {

        //Get the screen size
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();

        //Calculate the frame location
        int x = (screenSize.width - component.getWidth()) / 2;
        int y = (screenSize.height - component.getHeight()) / 2;

        //Set the new frame location
        component.setLocation(x, y);
    }
}

Related

  1. createExceptionDialog(Frame parent, String title, Throwable error)
  2. createProgressDialog(Frame parentFrame, String title, JProgressBar progressBar)
  3. enableAllComponents(final boolean enable, final Frame parent)
  4. enableAllComponentsExcept(final boolean enable, final Frame parent, final Component... components)
  5. ensureVisibilityAtParent(final JInternalFrame frame)
  6. fileOpen(Frame parent, String typename, String ext)
  7. findParentDialogOrFrame(Container container)
  8. getFirstParentFrameOrDialog(Component cmp)
  9. getFrame(Component parent)