Java JFrame display(JFrame parent, JInternalFrame dialog)

Here you can find the source of display(JFrame parent, JInternalFrame dialog)

Description

Display a dialog centered within the given frame.

License

Open Source License

Parameter

Parameter Description
parent the parent frame.
dialog the dialog.

Declaration

public static void display(JFrame parent, JInternalFrame dialog) 

Method Source Code

//package com.java2s;
// under the terms of the GNU Lesser General Public License as published

import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;

public class Main {
    /**// w w w  .j a  v  a2  s  . c  o m
     * Display a dialog centered within the given frame.
     *
     * @param parent the parent frame.
     * @param dialog the dialog.
     */
    public static void display(JFrame parent, JInternalFrame dialog) {
        center(parent, dialog);
        parent.getLayeredPane().add(dialog, JLayeredPane.POPUP_LAYER);
        dialog.setVisible(true);
    }

    /**
     * Centers the supplied dialog in its parent's bounds.
     */
    public static void center(JFrame parent, JInternalFrame dialog) {
        Dimension psize = parent.getSize();
        Dimension dsize = dialog.getSize();
        dialog.setLocation((psize.width - dsize.width) / 2, (psize.height - dsize.height) / 2);
    }
}

Related

  1. decorateFrame(JFrame frame, JMenuBar menuBar)
  2. deleteFile(String filepath, JFrame parent)
  3. dialogYesNo(JFrame frame, String title, String message, Object[] options)
  4. dispAlert(JFrame pFrame, String pTask, String pMessaggio)
  5. dispErrore(JFrame frame, String task, String mess)
  6. displayConfirmationMessage(JFrame parent, String message, String title)
  7. displayError(Exception e, JFrame jFrame)
  8. displayWindow(final JFrame window)
  9. dispose(final JFrame frame)