Java JFrame Parent showDoneDialog(Frame parent, String title, JComponent c)

Here you can find the source of showDoneDialog(Frame parent, String title, JComponent c)

Description

A simple dialog that allows one to show a user a given component.

License

Open Source License

Parameter

Parameter Description
parent The Frame to center upon.
title The tile for the dialog box.
c The component to display.

Declaration

public static void showDoneDialog(Frame parent, String title, JComponent c) 

Method Source Code

//package com.java2s;
/*//from   ww w  .j  a v a2s.c  om
This file is part of JFLICKS.
    
JFLICKS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
JFLICKS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with JFLICKS.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.awt.Frame;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;

import javax.swing.JSeparator;

public class Main {
    /**
     * A simple dialog that allows one to show a user a given component.
     * The idea is that the user can interact with the component and then
     * just dismiss the dialog with a "done" button.
     *
     * @param parent The Frame to center upon.
     * @param title The tile for the dialog box.
     * @param c The component to display.
     */
    public static void showDoneDialog(Frame parent, String title, JComponent c) {

        final JButton done = new JButton("Done");
        final JDialog dialog = new JDialog(parent, title, true);
        done.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {

                dialog.setVisible(false);
                done.setText("true");
                dialog.dispose();
            }
        });

        dialog.getContentPane().setLayout(new GridBagLayout());

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = 1;
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);

        dialog.getContentPane().add(c, gbc);

        gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.weighty = 0.0;
        gbc.gridwidth = 1;
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        dialog.getContentPane().add(new JSeparator(), gbc);

        gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.weighty = 0.0;
        gbc.gridwidth = 1;
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.NONE;
        gbc.insets = new Insets(4, 4, 4, 4);

        dialog.getContentPane().add(done, gbc);

        dialog.pack();
        dialog.setLocationRelativeTo(parent);
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        dialog.setVisible(true);
    }
}

Related

  1. rootFrame(@Nonnull Component component)
  2. runProgressDialog(Runnable runnable, Frame parentFrame, String title, int count)
  3. setFrameParentTitle(Container c, String s)
  4. showDialog(Frame aParent, String aMsg, String aTitle, int aType)
  5. showDialog(Frame parent, String title, JComponent c)
  6. showGeneralErrorDialog(Frame parent, String title, String message)
  7. showInfoDialog(final Frame parent, final String msg)
  8. showNothingIsSelectedForRemoveDialog(Frame parent)
  9. showSignatureUpdateErrorDialog(Frame parent, Throwable e)