Example usage for javax.swing JDialog dispose

List of usage examples for javax.swing JDialog dispose

Introduction

In this page you can find the example usage for javax.swing JDialog dispose.

Prototype

public void dispose() 

Source Link

Document

Releases all of the native screen resources used by this Window , its subcomponents, and all of its owned children.

Usage

From source file:com.gs.obevo.util.inputreader.DialogInputReader.java

@Override
public String readPassword(String promptMessage) {
    final JPasswordField jpf = new JPasswordField();
    JOptionPane jop = new JOptionPane(jpf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = jop.createDialog(promptMessage);
    dialog.addComponentListener(new ComponentAdapter() {
        @Override//  w  w  w .  j  a  v a2  s.  c o m
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    jpf.requestFocusInWindow();
                }
            });
        }
    });
    dialog.setVisible(true);
    int result = (Integer) jop.getValue();
    dialog.dispose();
    String password = null;
    if (result == JOptionPane.OK_OPTION) {
        password = new String(jpf.getPassword());
    }
    if (StringUtils.isEmpty(password)) {
        return null;
    } else {
        return password;
    }
}

From source file:com.raceup.fsae.test.TesterGui.java

/**
 * Shows dialog with info about unsuccessful test submission
 *///from   w  w  w. j  a  v  a 2  s.  co m
private void showUnSuccessfulTestSubmissionDialog() {
    totalTestTimer.start(); // re-start total timer

    String message = test.toString();
    message += "\nDon't worry, be happy: this box will automatically " + "close after "
            + Integer.toString(SECONDS_WAIT_BETWEEN_SUBMISSIONS) + " seconds of your " + "submission.\nEnjoy.";

    JOptionPane opt = new JOptionPane(message, JOptionPane.WARNING_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
            new Object[] {}); // no buttons
    final JDialog dlg = opt.createDialog("Error");
    new Thread(() -> {
        try {
            Thread.sleep(SECONDS_WAIT_BETWEEN_SUBMISSIONS * 1000);
            dlg.dispose();
        } catch (Throwable t) {
            System.err.println(t.toString());
        }
    }).start();
    dlg.setVisible(true);
}

From source file:com.gs.obevo.util.inputreader.DialogInputReader.java

@Override
public String readLine(String promptMessage) {
    final JTextField juf = new JTextField();
    JOptionPane juop = new JOptionPane(juf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog userDialog = juop.createDialog(promptMessage);
    userDialog.addComponentListener(new ComponentAdapter() {
        @Override/*from   w ww .  j  a  va2s. c  om*/
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    juf.requestFocusInWindow();
                }
            });
        }
    });
    userDialog.setVisible(true);
    int uresult = (Integer) juop.getValue();
    userDialog.dispose();
    String userName = null;
    if (uresult == JOptionPane.OK_OPTION) {
        userName = new String(juf.getText());
    }

    if (StringUtils.isEmpty(userName)) {
        return null;
    } else {
        return userName;
    }
}

From source file:livecanvas.mesheditor.MeshEditor.java

private void showImage(Image image) {
    if (image == null) {
        return;/*from w  w w.  ja va  2s .  c  o m*/
    }
    JDialog d = new JDialog(JOptionPane.getFrameForComponent(MeshEditor.this), "Image View", true);
    d.setContentPane(new JLabel(new ImageIcon(image)));
    d.pack();
    d.setLocationRelativeTo(d.getParent());
    d.setVisible(true);
    d.dispose();
}

From source file:de.dakror.virtualhub.server.dialog.BackupEditDialog.java

public static void show() throws JSONException {
    final JDialog dialog = new JDialog(Server.currentServer.frame, "Backup-Einstellungen", true);
    dialog.setSize(400, 250);//from  w w w  .jav a  2s.c  o  m
    dialog.setLocationRelativeTo(Server.currentServer.frame);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    JPanel cp = new JPanel(new SpringLayout());
    cp.add(new JLabel("Zielverzeichnis:"));
    JPanel panel = new JPanel();
    final JTextField path = new JTextField((Server.currentServer.settings.has("backup.path")
            ? Server.currentServer.settings.getString("backup.path")
            : ""), 10);
    panel.add(path);
    panel.add(new JButton(new AbstractAction("Whlen...") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser jfc = new JFileChooser((path.getText().length() > 0 ? new File(path.getText())
                    : new File(System.getProperty("user.home"))));
            jfc.setFileHidingEnabled(false);
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jfc.setDialogTitle("Backup-Zielverzeichnis whlen");

            if (jfc.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION)
                path.setText(jfc.getSelectedFile().getPath().replace("\\", "/"));
        }
    }));

    cp.add(panel);

    cp.add(new JLabel(""));
    cp.add(new JLabel(""));

    cp.add(new JButton(new AbstractAction("Abbrechen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    }));
    cp.add(new JButton(new AbstractAction("Speichern") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (path.getText().length() > 0)
                    Server.currentServer.settings.put("backup.path", path.getText());
                dialog.dispose();
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        }
    }));

    SpringUtilities.makeCompactGrid(cp, 3, 2, 6, 6, 6, 6);
    dialog.setContentPane(cp);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:fr.duminy.components.swing.form.JFormPane.java

/**
 * Display this form in a dialog.//from  w w  w. j av a 2  s  .co m
 *
 * @param parentComponent The parent component of the dialog.
 * @return The final value entered by the user in the dialog, or null if it was cancelled.
 */
public B showDialog(Component parentComponent) {
    Window parentWindow;
    if (parentComponent == null) {
        parentWindow = JOptionPane.getRootFrame();
    } else if (parentComponent instanceof Window) {
        parentWindow = (Window) parentComponent;
    } else {
        parentWindow = SwingUtilities.getWindowAncestor(parentComponent);
    }
    final JDialog dialog = new JDialog(parentWindow, title, Dialog.ModalityType.APPLICATION_MODAL);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setContentPane(this);
    dialog.setResizable(false);
    setBorder(null);
    final MutableObject<Boolean> validated = new MutableObject<>(false);
    FormListener<B> listener = new FormListener<B>() {
        @Override
        public void formValidated(Form<B> form) {
            validated.setValue(true);
            dialog.dispose();
        }

        @Override
        public void formCancelled(Form<B> form) {
            dialog.dispose();
        }
    };

    try {
        addFormListener(listener);
        dialog.pack();
        dialog.setVisible(true);
        return validated.getValue() ? getValue() : null;
    } finally {
        removeFormListener(listener);
    }
}

From source file:jatoo.proxy.dialog.ProxyDialog.java

/**
 * Shows the dialog relative to the specified owner.
 *///from   ww w.java  2 s. co  m
public static synchronized void show(Component owner) {

    JDialog dialogTmp;

    if (owner == null) {
        dialogTmp = new JDialog();
    } else {
        dialogTmp = new JDialog(SwingUtilities.getWindowAncestor(owner));
    }

    final JDialog dialog = dialogTmp;

    //
    // the panel

    final ProxyDialogPanel dialogPanel = PROXY_DIALOG_PANEL_FACTORY.createDialogPanel();

    try {

        Proxy proxy = new Proxy();
        proxy.load();

        dialogPanel.setProxyEnabled(proxy.isEnabled());
        dialogPanel.setHost(proxy.getHost());
        dialogPanel.setPort(proxy.getPort());
        dialogPanel.setProxyRequiringAuthentication(proxy.isRequiringAuthentication());
        dialogPanel.setUsername(proxy.getUsername());
        dialogPanel.setPassword(proxy.getPassword());
    }

    catch (FileNotFoundException e) {
        // do nothing, maybe is the first time and the file is missing
    }

    catch (Exception e) {
        logger.error("Failed to load the properties.", e);
    }

    //
    // buttons

    JButton okButton = new JButton("Ok");
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            try {

                if (dialogPanel.isProxyEnabled()) {

                    if (dialogPanel.isProxyRequiringAuthentication()) {
                        ProxyUtils.setProxy(dialogPanel.getHost(), dialogPanel.getPort(),
                                dialogPanel.getUsername(), dialogPanel.getPassword());
                    } else {
                        ProxyUtils.setProxy(dialogPanel.getHost(), dialogPanel.getPort());
                    }
                }

                else {
                    ProxyUtils.removeProxy();
                }

                dialog.dispose();
            }

            catch (Exception e) {
                JOptionPane.showMessageDialog(dialog, "Failed to set the proxy:\n" + e.toString());
                return;
            }

            try {

                Proxy proxy = new Proxy();

                proxy.setEnabled(dialogPanel.isProxyEnabled());
                proxy.setUsername(dialogPanel.getUsername());
                proxy.setPassword(dialogPanel.getPassword());
                proxy.setRequiringAuthentication(dialogPanel.isProxyRequiringAuthentication());
                proxy.setHost(dialogPanel.getHost());
                proxy.setPort(dialogPanel.getPort());

                proxy.store();
            }

            catch (Exception e) {
                logger.error("Failed to save the properties.", e);
            }
        }
    });

    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    //
    // layout dialog

    dialogPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel buttonsGroup = new JPanel(new GridLayout(1, 2, 5, 5));
    buttonsGroup.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    buttonsGroup.add(okButton);
    buttonsGroup.add(cancelButton);

    JPanel buttonsPanel = new JPanel(new BorderLayout());
    buttonsPanel.add(buttonsGroup, BorderLayout.LINE_END);

    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.add(dialogPanel, BorderLayout.CENTER);
    contentPane.add(buttonsPanel, BorderLayout.PAGE_END);

    //
    // setup dialog

    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setTitle("Proxy Settings");
    dialog.setContentPane(contentPane);
    dialog.pack();
    dialog.setLocationRelativeTo(dialog.getOwner());
    dialog.setModal(true);

    //
    // and show

    dialog.setVisible(true);
}

From source file:idontwant2see.IDontWant2See.java

public ActionMenu getButtonAction() {
    final ContextMenuAction baseAction = new ContextMenuAction(mLocalizer.msg("name", "I don't want to see!"),
            createImageIcon("apps", "idontwant2see", 16));

    final ContextMenuAction openExclusionList = new ContextMenuAction(
            mLocalizer.msg("editExclusionList", "Edit exclusion list"),
            createImageIcon("apps", "idontwant2see", 16));
    openExclusionList.putValue(Plugin.BIG_ICON, createImageIcon("apps", "idontwant2see", 22));
    openExclusionList.setActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            final Window w = UiUtilities.getLastModalChildOf(getParentFrame());

            JDialog temDlg = null;

            if (w instanceof JDialog) {
                temDlg = new JDialog((JDialog) w, true);
            } else {
                temDlg = new JDialog((JFrame) w, true);
            }/*w w w. j  av a  2 s  .c  o  m*/

            final JDialog exclusionListDlg = temDlg;
            exclusionListDlg.setTitle(mLocalizer.msg("name", "I don't want to see!") + " - "
                    + mLocalizer.msg("editExclusionList", "Edit exclusion list"));

            UiUtilities.registerForClosing(new WindowClosingIf() {
                public void close() {
                    exclusionListDlg.dispose();
                }

                public JRootPane getRootPane() {
                    return exclusionListDlg.getRootPane();
                }
            });

            final ExclusionTablePanel exclusionPanel = new ExclusionTablePanel(mSettings);

            final JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK));
            ok.addActionListener(new ActionListener() {
                public void actionPerformed(final ActionEvent e) {
                    exclusionPanel.saveSettings(mSettings);
                    exclusionListDlg.dispose();
                }
            });

            final JButton cancel = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL));
            cancel.addActionListener(new ActionListener() {
                public void actionPerformed(final ActionEvent e) {
                    exclusionListDlg.dispose();
                }
            });

            final FormLayout layout = new FormLayout("0dlu:grow,default,3dlu,default",
                    "fill:500px:grow,2dlu,default,5dlu,default");
            layout.setColumnGroups(new int[][] { { 2, 4 } });

            final CellConstraints cc = new CellConstraints();
            final PanelBuilder pb = new PanelBuilder(layout, (JPanel) exclusionListDlg.getContentPane());
            pb.setDefaultDialogBorder();

            pb.add(exclusionPanel, cc.xyw(1, 1, 4));
            pb.addSeparator("", cc.xyw(1, 3, 4));
            pb.add(ok, cc.xy(2, 5));
            pb.add(cancel, cc.xy(4, 5));

            layoutWindow("exclusionListDlg", exclusionListDlg, new Dimension(600, 450));
            exclusionListDlg.setVisible(true);
        }
    });

    final ContextMenuAction undo = new ContextMenuAction(
            mLocalizer.msg("undoLastExclusion", "Undo last exclusion"),
            createImageIcon("actions", "edit-undo", 16));
    undo.putValue(Plugin.BIG_ICON, createImageIcon("actions", "edit-undo", 22));
    undo.setActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            String lastEnteredExclusionString = mSettings.getLastEnteredExclusionString();
            if (lastEnteredExclusionString.length() > 0) {
                for (int i = mSettings.getSearchList().size() - 1; i >= 0; i--) {
                    if (mSettings.getSearchList().get(i).getSearchText().equals(lastEnteredExclusionString)) {
                        mSettings.getSearchList().remove(i);
                    }
                }

                mSettings.setLastEnteredExclusionString("");

                updateFilter(true);
            }
        }
    });

    return new ActionMenu(baseAction, new Action[] { openExclusionList, undo });
}

From source file:net.sf.jabref.gui.openoffice.OpenOfficePanel.java

private void connect(boolean auto) {
    String ooJarsDirectory;//from ww w.j a v a2 s  . c om
    if (auto) {
        AutoDetectPaths adp = new AutoDetectPaths(diag, preferences);
        if (adp.runAutodetection()) {
            autoDetected = true;
            dialogOkPressed = true;
            diag.dispose();
        } else if (!adp.canceled()) {
            JOptionPane.showMessageDialog(diag, Localization.lang("Autodetection failed"),
                    Localization.lang("Autodetection failed"), JOptionPane.ERROR_MESSAGE);
        } else {
            frame.setStatus(Localization.lang("Operation canceled."));
        }
        if (!autoDetected) {
            return;
        }

        ooJarsDirectory = preferences.getJarsPath();
        sOffice = preferences.getExecutablePath();
    } else { // Manual connect

        showConnectDialog();
        if (!dialogOkPressed) {
            return;
        }

        String ooPath = preferences.getOOPath();
        String ooJars = preferences.getJarsPath();
        sOffice = preferences.getExecutablePath();

        if (OS.WINDOWS) {
            ooJarsDirectory = ooPath + OpenOfficePreferences.WINDOWS_JARS_SUBPATH;
            sOffice = ooPath + OpenOfficePreferences.WINDOWS_EXECUTABLE_SUBPATH
                    + OpenOfficePreferences.WINDOWS_EXECUTABLE;
        } else if (OS.OS_X) {
            sOffice = ooPath + OpenOfficePreferences.OSX_EXECUTABLE_SUBPATH
                    + OpenOfficePreferences.OSX_EXECUTABLE;
            ooJarsDirectory = ooPath + OpenOfficePreferences.OSX_JARS_SUBPATH;
        } else {
            // Linux:
            ooJarsDirectory = ooJars + "/program/classes";
        }
    }

    // Add OO jars to the classpath:
    try {
        List<File> jarFiles = Arrays.asList(new File(ooJarsDirectory, "unoil.jar"),
                new File(ooJarsDirectory, "jurt.jar"), new File(ooJarsDirectory, "juh.jar"),
                new File(ooJarsDirectory, "ridl.jar"));
        List<URL> jarList = new ArrayList<>(jarFiles.size());
        for (File jarFile : jarFiles) {
            if (!jarFile.exists()) {
                throw new IOException("File not found: " + jarFile.getPath());
            }
            jarList.add(jarFile.toURI().toURL());
        }
        addURL(jarList);

        // Show progress dialog:
        final JDialog progDiag = new AutoDetectPaths(diag, preferences).showProgressDialog(diag,
                Localization.lang("Connecting"), Localization.lang("Please wait..."), false);
        getWorker().run(); // Do the actual connection, using Spin to get off the EDT.
        progDiag.dispose();
        diag.dispose();
        if (ooBase == null) {
            throw connectException;
        }

        if (ooBase.isConnectedToDocument()) {
            frame.output(Localization.lang("Connected to document") + ": "
                    + ooBase.getCurrentDocumentTitle().orElse(""));
        }

        // Enable actions that depend on Connect:
        selectDocument.setEnabled(true);
        pushEntries.setEnabled(true);
        pushEntriesInt.setEnabled(true);
        pushEntriesEmpty.setEnabled(true);
        pushEntriesAdvanced.setEnabled(true);
        update.setEnabled(true);
        merge.setEnabled(true);
        manageCitations.setEnabled(true);

    } catch (UnsatisfiedLinkError e) {
        LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", e);
        JOptionPane.showMessageDialog(frame,
                Localization.lang("Unable to connect. One possible reason is that JabRef "
                        + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode."));
    } catch (IOException e) {
        LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", e);
        JOptionPane.showMessageDialog(frame,
                Localization.lang("Could not connect to running OpenOffice/LibreOffice.") + "\n"
                        + Localization.lang(
                                "Make sure you have installed OpenOffice/LibreOffice with Java support.")
                        + "\n"
                        + Localization.lang("If connecting manually, please verify program and library paths.")
                        + "\n" + "\n" + Localization.lang("Error message:") + " " + e.getMessage());
    }
}

From source file:net.sf.jabref.openoffice.OpenOfficePanel.java

private void connect(boolean auto) {
    String ooBaseDirectory;//  w  w  w  .ja v a 2 s.  co m
    if (auto) {
        AutoDetectPaths adp = new AutoDetectPaths(diag);
        if (adp.runAutodetection()) {
            autoDetected = true;
            dialogOkPressed = true;
            diag.dispose();
        } else if (!adp.cancelled()) {
            JOptionPane.showMessageDialog(diag, Localization.lang("Autodetection failed"),
                    Localization.lang("Autodetection failed"), JOptionPane.ERROR_MESSAGE);
        }
        if (!autoDetected) {
            return;
        }

        ooBaseDirectory = Globals.prefs.get(JabRefPreferences.OO_JARS_PATH);
        sOffice = Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH);
    } else { // Manual connect

        showConnectDialog();
        if (!dialogOkPressed) {
            return;
        }

        String ooPath = Globals.prefs.get(JabRefPreferences.OO_PATH);
        String ooJars = Globals.prefs.get(JabRefPreferences.OO_JARS_PATH);
        sOffice = Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH);

        if (OS.WINDOWS) {
            ooBaseDirectory = ooPath + "\\program\\classes";
            sOffice = ooPath + "\\program\\soffice.exe";
        } else if (OS.OS_X) {
            sOffice = ooPath + "/Contents/MacOS/soffice.bin";
            ooBaseDirectory = ooPath + "/Contents/Resources/java";
        } else {
            // Linux:
            ooBaseDirectory = ooJars + "/program/classes";
        }
    }

    // Add OO jars to the classpath:
    try {
        List<File> jarFiles = Arrays.asList(new File(ooBaseDirectory, "unoil.jar"),
                new File(ooBaseDirectory, "jurt.jar"), new File(ooBaseDirectory, "juh.jar"),
                new File(ooBaseDirectory, "ridl.jar"));
        List<URL> jarList = new ArrayList<>(jarFiles.size());
        for (File jarFile : jarFiles) {
            if (!jarFile.exists()) {
                throw new IOException("File not found: " + jarFile.getPath());
            }
            jarList.add(jarFile.toURI().toURL());
        }
        addURL(jarList);

        // Show progress dialog:
        final JDialog progDiag = new AutoDetectPaths(diag).showProgressDialog(diag,
                Localization.lang("Connecting"), Localization.lang("Please wait..."), false);
        getWorker().run(); // Do the actual connection, using Spin to get off the EDT.
        progDiag.dispose();
        diag.dispose();
        if (ooBase == null) {
            throw connectException;
        }

        if (ooBase.isConnectedToDocument()) {
            frame.output(Localization.lang("Connected to document") + ": "
                    + ooBase.getCurrentDocumentTitle().orElse(""));
        }

        // Enable actions that depend on Connect:
        selectDocument.setEnabled(true);
        pushEntries.setEnabled(true);
        pushEntriesInt.setEnabled(true);
        pushEntriesEmpty.setEnabled(true);
        pushEntriesAdvanced.setEnabled(true);
        update.setEnabled(true);
        merge.setEnabled(true);
        manageCitations.setEnabled(true);

    } catch (UnsatisfiedLinkError e) {
        LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", e);
        JOptionPane.showMessageDialog(frame,
                Localization.lang("Unable to connect. One possible reason is that JabRef "
                        + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode."));
    } catch (IOException e) {
        LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", e);
        JOptionPane.showMessageDialog(frame,
                Localization.lang("Could not connect to running OpenOffice.") + "\n"
                        + Localization.lang("Make sure you have installed OpenOffice with Java support.") + "\n"
                        + Localization.lang("If connecting manually, please verify program and library paths.")
                        + "\n" + "\n" + Localization.lang("Error message:") + " " + e.getMessage());
    }
}