Example usage for javax.swing WindowConstants DISPOSE_ON_CLOSE

List of usage examples for javax.swing WindowConstants DISPOSE_ON_CLOSE

Introduction

In this page you can find the example usage for javax.swing WindowConstants DISPOSE_ON_CLOSE.

Prototype

int DISPOSE_ON_CLOSE

To view the source code for javax.swing WindowConstants DISPOSE_ON_CLOSE.

Click Source Link

Document

The dispose-window default window close operation.

Usage

From source file:Main.java

public static void showFrame(JFrame frame, JFrame parent) {
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.pack();// w  w  w  . j  av  a2 s.co  m
    frame.setLocation(parent.getX() + (parent.getWidth() - frame.getWidth()) / 2,
            parent.getY() + (parent.getHeight() - frame.getHeight()) / 2);
    frame.setVisible(true);
}

From source file:Main.java

public static boolean showModalDialogOnEDT(JComponent contents, String title, String okButtonMessage,
        String cancelButtonMessage, ModalityType modalityType, final boolean systemExitOnDisposed) {

    class Result {
        boolean OK = false;
    }/*from w w  w.  j  av  a 2s . c  o  m*/
    final Result result = new Result();

    final JDialog dialog = new JDialog((Frame) null, title, true) {
        @Override
        public void dispose() {
            super.dispose();
            if (systemExitOnDisposed) {
                System.exit(0);
            }
        }
    };

    // ensure it doesn't block other dialogs
    if (modalityType != null) {
        dialog.setModalityType(modalityType);
    }

    // See http://stackoverflow.com/questions/1343542/how-do-i-close-a-jdialog-and-have-the-window-event-listeners-be-notified
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
    if (okButtonMessage != null) {
        buttonPane.add(new JButton(new AbstractAction(okButtonMessage) {

            @Override
            public void actionPerformed(ActionEvent e) {
                result.OK = true;
                dialog.dispose();
            }
        }));
    }

    if (cancelButtonMessage != null) {
        buttonPane.add(new JButton(new AbstractAction(cancelButtonMessage) {

            @Override
            public void actionPerformed(ActionEvent e) {
                dialog.dispose();
            }
        }));
    }

    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BorderLayout());
    panel.add(contents, BorderLayout.CENTER);
    panel.add(buttonPane, BorderLayout.SOUTH);

    // startup frame
    dialog.getContentPane().add(panel);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.pack();

    // This hopefully centres the dialog even though the parameter is null 
    // see http://stackoverflow.com/questions/213266/how-do-i-center-a-jdialog-on-screen
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);

    return result.OK;
}

From source file:Test.java

public Test() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    d.getContentPane().add(new JLabel("Click the OK button"), BorderLayout.CENTER);
    JButton closeIt = new JButton("OK");
    closeIt.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Closing dialog");
            d.dispose();/*from w  ww.jav  a2s.  com*/
        }
    });
    d.getContentPane().add(closeIt, BorderLayout.SOUTH);
    d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    d.pack();

    getContentPane().add(new JLabel("Placeholder label"));
    pack();
    setSize(200, 200);
    setVisible(true);
    d.setVisible(true);
}

From source file:com.mirth.connect.client.ui.attachments.IdentityAttachmentDialog.java

public IdentityAttachmentDialog(AttachmentHandlerProperties attachmentHandlerProperties) {
    super(PlatformUI.MIRTH_FRAME, true);
    this.parent = PlatformUI.MIRTH_FRAME;
    initComponents();/*from   w ww  .  j a  v a 2  s .co m*/
    initToolTips();
    initLayout();
    setProperties(attachmentHandlerProperties);

    setTitle("Set Attachment Properties");
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setPreferredSize(new Dimension(309, 130));
    pack();
    setLocationRelativeTo(parent);
    setVisible(true);
}

From source file:org.matsim.contrib.util.chart.ChartWindowUtils.java

private static JDialog newChartDialog(JFreeChart chart, String title, boolean modal) {
    chart.setTitle(title);/*from   w  w  w . j  ava2s  .  c  om*/
    JDialog dialog = new JDialog();
    dialog.setTitle(title);
    dialog.setContentPane(new ChartPanel(chart));
    dialog.setModal(modal);
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    return dialog;
}

From source file:edu.pdi2.visual.ViewSignature.java

public ViewSignature(String name, byte[] sign) {
    super();/* w  w  w . j a  v a  2  s  .  com*/
    XYSeries signature = new XYSeries("Signature");
    for (int i = 0; i < sign.length; i++) {
        signature.add(i, sign[i]);
    }

    JFrame frame = new JFrame();
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(signature);
    JFreeChart signatureG = ChartFactory.createXYLineChart("Signature " + name, "Valorx", "Valory", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartpanel = new ChartPanel(signatureG);
    chartpanel.setPreferredSize(new Dimension(390, 290));
    frame.setContentPane(chartpanel);
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    frame.pack();
    frame.setSize(400, 300);
    frame.setVisible(true);
    if (name == " RED")
        frame.setLocation(0, 300);
    else
        frame.setLocation(400, 300);

}

From source file:gtu._work.ui.ObnfJetDeleteUI.java

private void initGUI() {
    try {/* w  ww.j a va 2s.c o  m*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jLabel1 = new JLabel();
                    jPanel1.add(jLabel1);
                    jLabel1.setText("\u8acb\u586b\u5165\u76ee\u9304");
                }
                {
                    srcDirText = new JTextField();
                    JCommonUtil.jTextFieldSetFilePathMouseEvent(srcDirText, true);
                    jPanel1.add(srcDirText);
                    srcDirText.setPreferredSize(new java.awt.Dimension(288, 22));
                }
                {
                    executeBtn = new JButton();
                    jPanel1.add(executeBtn);
                    executeBtn.setText("\u57f7\u884c");
                    executeBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            executeBtnPerformed();
                        }
                    });
                }
                {
                    excludeArea = new JTextArea();
                    jPanel1.add(excludeArea);
                    excludeArea.setPreferredSize(new java.awt.Dimension(418, 238));
                }
            }
        }
        pack();
        this.setSize(511, 339);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:algo.PlotBar.java

public PlotBar(String applicationTitle, String chartTitle) throws FileNotFoundException, IOException {
    super(applicationTitle);
    JFreeChart barChart = ChartFactory.createBarChart(chartTitle, "Algorithms", "Execution Time(ms)",
            createDataset(), PlotOrientation.VERTICAL, true, true, false);
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    ChartPanel chartPanel = new ChartPanel(barChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 420));
    setContentPane(chartPanel);//w  ww.  ja v a 2 s.c  o  m
}

From source file:gtu._work.ui.JermyP100UI.java

private void initGUI() {
    try {/*from  w w  w .j a v a 2s.c  o  m*/
        FlowLayout thisLayout = new FlowLayout();
        getContentPane().setLayout(thisLayout);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            jLabel1 = new JLabel();
            getContentPane().add(jLabel1);
            jLabel1.setText("FileP100.xls");
            jLabel1.setPreferredSize(new java.awt.Dimension(68, 15));
        }
        {
            fileP100Text = new JTextField();
            JCommonUtil.jTextFieldSetFilePathMouseEvent(fileP100Text, false);
            getContentPane().add(fileP100Text);
            fileP100Text.setPreferredSize(new java.awt.Dimension(340, 22));
        }
        {
            label2 = new JLabel();
            getContentPane().add(label2);
            getContentPane().add(label2);
            label2.setText("RCDFP100.xls");
            label2.setPreferredSize(new java.awt.Dimension(84, 15));
        }
        {
            rcdfp100Text = new JTextField();
            JCommonUtil.jTextFieldSetFilePathMouseEvent(rcdfp100Text, false);
            getContentPane().add(rcdfp100Text);
            rcdfp100Text.setPreferredSize(new java.awt.Dimension(340, 22));
        }
        {
            executeBtn = new JButton();
            getContentPane().add(executeBtn);
            executeBtn.setText("\u7522\u751f\u532f\u51fa\u6a94");
            executeBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    if (StringUtils.isBlank(rcdfp100Text.getText())) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("RCDFP100.xls");
                        return;
                    }
                    File rcdfp100File = new File(StringUtils.defaultString(rcdfp100Text.getText()));
                    if (!rcdfp100File.exists()) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("RCDFP100.xls");
                        return;
                    }

                    if (StringUtils.isBlank(fileP100Text.getText())) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("FileP100.xls");
                        return;
                    }
                    File fileP100File = new File(StringUtils.defaultString(fileP100Text.getText()));
                    if (!rcdfp100File.exists()) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("FileP100.xls");
                        return;
                    }

                    try {
                        TestForJermy test = new TestForJermy();
                        test.execute(fileP100File, rcdfp100File,
                                PropertiesUtil.getJarCurrentPath(JermyP100UI.class));
                        File outputFile = test.getOutputCvs();
                        JCommonUtil._jOptionPane_showMessageDialog_info(
                                ":\n" + outputFile.getAbsolutePath());
                    } catch (Exception ex) {
                        JCommonUtil.handleException(ex);
                    }
                }
            });
        }
        pack();
        this.setSize(457, 146);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:OAT.ui.AbstractChartFrame.java

private void initComponent() {
    setJMenuBar(new MainMenuBar(this));

    chartPanel.setPreferredSize(getChartPanelSize());
    setContentPane(chartPanel);//from w  ww .  j a va2 s  .  c om

    setDefaultCloseOperation(
            disposeOnClose() ? WindowConstants.DISPOSE_ON_CLOSE : WindowConstants.HIDE_ON_CLOSE);

    if (hideWhenFocusLost()) {
        addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent e) {
                setVisible(false);
            }
        });
    }

    init();

    //pack and display
    pack();
}