Dialog Panel : JDialog « Swing « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » Swing » JDialog 




/*
 * Enhydra Java Application Server Project
 *
 * The contents of this file are subject to the Enhydra Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License on
 * the Enhydra web site ( http://www.enhydra.org/ ).
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific terms governing rights and limitations
 * under the License.
 *
 * The Initial Developer of the Enhydra Application Server is Lutris
 * Technologies, Inc. The Enhydra Application Server and portions created
 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
 * All Rights Reserved.
 *
 * Contributor(s):
 *
 */

// Standard imports
import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Point;
import java.awt.event.WindowEvent;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JOptionPane;

//
public class DialogPanel extends JPanel {
    public final static int CANCEL_OPTION = JOptionPane.CANCEL_OPTION;
    public final static int OK_OPTION = JOptionPane.OK_OPTION;

    //
    private int             option = DialogPanel.CANCEL_OPTION;
    private LocalDialog     dialog = null;
    private Window          owner = null;
    private boolean         windowClose = false;
    private boolean         standalone = false;
    private boolean         modal = true;
    private String          title = new String();

    public Window getOwner() {
        return owner;
    }

    public void setOwner(Window w) {
        owner = w;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String t) {
        title = t;
    }

    public boolean isModal() {
        return modal;
    }

    public void setModal(boolean b) {
        modal = b;
    }

    public int getOption() {
        return option;
    }

    public void setOption(int o) {
        option = o;
    }

    public LocalDialog getDialog() {
        return dialog;
    }

    public void startDialogThread() {
        Thread dialogThread = new Thread() {
            public void run() {
                showDialog();
            }

        };

        dialogThread.start();
    }

    public int showDialog() {
        BorderLayout layout = null;
        Point        cp = null;

        if (dialog == null) {
            if (getOwner() == null) {
                dialog = new LocalDialog();
            else if (getOwner() instanceof Frame) {
                dialog = new LocalDialog((FramegetOwner());
            else if (getOwner() instanceof Dialog) {
                dialog = new LocalDialog((DialoggetOwner());
            else {
                dialog = new LocalDialog();
            }
        }
        dialog.setModal(isModal());
        dialog.setTitle(getTitle());
        layout = new BorderLayout();
        dialog.getRootPane().setLayout(layout);
        dialog.getRootPane().add(this, BorderLayout.CENTER);
        dialog.pack();

  
        dialog.show();
        return option;
    }

    //
    // PROTECTED
    //
    protected void hideDialog() {
        if (dialog != null) {
            dialog.setVisible(false);
        }
    }

    protected void clearDialog() {
        if (dialog != null) {
            dialog.setVisible(false);
            dialog.getRootPane().removeAll();
            dialog.removeAll();
            dialog.dispose();
        }
        if (isStandalone()) {
            System.exit(0);
        }
    }

    protected boolean isWindowClose() {
        return windowClose;
    }

    protected void setWindowClose(boolean b) {
        windowClose = b;
    }

    protected boolean isStandalone() {
        return standalone;
    }

    protected void setStandalone(boolean b) {
        standalone = b;
    }

    private class LocalDialog extends JDialog {
        public LocalDialog() {
            super();
        }

        public LocalDialog(Dialog owner) {
            super(owner);
        }

        public LocalDialog(Frame owner) {
            super(owner);
        }

        protected void processWindowEvent(WindowEvent e) {
            if (isWindowClose()) {
                if (e.getID() == WindowEvent.WINDOW_CLOSING) {
                    clearDialog();
                }
                super.processWindowEvent(e);
            }
        }

    }
}














14.74.JDialog
14.74.1.Dialog Introduction
14.74.2.A Simple Modal DialogA Simple Modal Dialog
14.74.3.JDialog is specify that pressing the Escape key cancels the dialog.JDialog is specify that pressing the Escape key cancels the dialog.
14.74.4.Address DialogAddress Dialog
14.74.5.Set Default Close Operation for Dialog
14.74.6.Extending JDialog
14.74.7.extends JDialog to create your own dialog
14.74.8.The base class for standard dialogs.
14.74.9.A dialog that presents the user with a sequence of steps for completing a task.
14.74.10.Positions the specified dialog at a position relative to its parent.
14.74.11.A dialog allow selection and a font and its associated info.
14.74.12.Font Chooser extends javax.swing.JDialog
14.74.13.FontChooser by Noah w
14.74.14.Dialog Panel
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.