Example usage for javax.swing JDialog pack

List of usage examples for javax.swing JDialog pack

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public void pack() 

Source Link

Document

Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.

Usage

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

private void displayStyle(OOBibStyle style) {
    // Make a dialog box to display the contents:
    final JDialog dd = new JDialog(diag, style.getName(), true);

    JTextArea ta = new JTextArea(style.getLocalCopy());
    ta.setEditable(false);//from  w ww  . j av a  2 s  .c o  m
    JScrollPane sp = new JScrollPane(ta);
    sp.setPreferredSize(new Dimension(700, 500));
    dd.getContentPane().add(sp, BorderLayout.CENTER);
    JButton okButton = new JButton(Localization.lang("OK"));
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(okButton);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    dd.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    okButton.addActionListener(actionEvent -> dd.dispose());
    dd.pack();
    dd.setLocationRelativeTo(diag);
    dd.setVisible(true);
}

From source file:org.moeaframework.analysis.plot.Plot.java

/**
 * Displays the chart in a blocking JDialog.
 * //from   w w w .ja  v a  2  s .  c om
 * @param width the width of the chart
 * @param height the height of the chart
 * @return the window that was created
 */
public JDialog showDialog(int width, int height) {
    JDialog frame = new JDialog();

    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(getChartPanel(), BorderLayout.CENTER);

    frame.setPreferredSize(new Dimension(width, height));
    frame.pack();

    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setTitle("MOEA Framework Plot");
    frame.setModalityType(ModalityType.APPLICATION_MODAL);
    frame.setVisible(true);

    return frame;
}

From source file:net.sf.taverna.t2.workbench.ui.servicepanel.actions.AddServiceProviderAction.java

@Override
public void actionPerformed(ActionEvent e) {
    if (confProvider instanceof CustomizedConfigurePanelProvider) {
        final CustomizedConfigurePanelProvider provider = (CustomizedConfigurePanelProvider) confProvider;
        provider.createCustomizedConfigurePanel(new CustomizedConfigureCallBack() {
            @Override//www.  j  ava 2  s . co  m
            public Configuration getTemplateConfig() {
                return (Configuration) provider.getConfiguration().clone();
            }

            @Override
            public ServiceDescriptionRegistry getServiceDescriptionRegistry() {
                return AddServiceProviderAction.this.getServiceDescriptionRegistry();
            }

            @Override
            public void newProviderConfiguration(Configuration providerConfig) {
                addNewProvider(providerConfig);
            }
        });
        return;
    }

    Configuration configuration;
    try {
        configuration = (Configuration) confProvider.getConfiguration().clone();
    } catch (Exception ex) {
        throw new RuntimeException("Can't clone configuration bean", ex);
    }
    JPanel buildEditor = buildEditor(configuration);
    String title = "Add " + confProvider.getName();
    JDialog dialog = new HelpEnabledDialog(getMainWindow(), title, true, null);
    JPanel iconPanel = new JPanel();
    iconPanel.add(new JLabel(confProvider.getIcon()), NORTH);
    dialog.add(iconPanel, WEST);
    dialog.add(buildEditor, CENTER);
    JPanel buttonPanel = new JPanel(new BorderLayout());
    final AddProviderAction addProviderAction = new AddProviderAction(configuration, dialog);
    JButton addProviderButton = new JButton(addProviderAction);
    buttonPanel.add(addProviderButton, WEST);

    dialog.add(buttonPanel, SOUTH);
    // When user presses "Return" key fire the action on the "Add" button
    addProviderButton.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == VK_ENTER)
                addProviderAction.actionPerformed(null);
        }
    });
    dialog.getRootPane().setDefaultButton(addProviderButton);

    // dialog.setSize(buttonPanel.getPreferredSize());
    dialog.pack();
    dialog.setLocationRelativeTo(owner);
    //      dialog.setLocation(owner.getLocationOnScreen().x + owner.getWidth(),
    //            owner.getLocationOnScreen().y + owner.getHeight());
    dialog.setVisible(true);
}

From source file:com.sshtools.common.ui.SshToolsConnectionPanel.java

/**
 *
 *
 * @param parent//from w  w w.j a  va  2 s  .co m
 * @param profile
 * @param optionalTabs
 *
 * @return
 */
public static SshToolsConnectionProfile showConnectionDialog(Component parent,
        SshToolsConnectionProfile profile, SshToolsConnectionTab[] optionalTabs) {
    //  If no properties are provided, then use the default
    if (profile == null) {
        int port = DEFAULT_PORT;
        String port_S = Integer.toString(DEFAULT_PORT);
        port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S);
        try {
            port = Integer.parseInt(port_S);
        } catch (NumberFormatException e) {
            log.warn("Could not parse the port number from defaults file (property name"
                    + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ").");
        }
        profile = new SshToolsConnectionProfile();
        profile.setHost(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_HOST, ""));
        profile.setPort(PreferencesStore.getInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, port));
        profile.setUsername(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_USER, ""));

    }

    final SshToolsConnectionPanel conx = new SshToolsConnectionPanel(true);

    if (optionalTabs != null) {
        for (int i = 0; i < optionalTabs.length; i++) {
            conx.addTab(optionalTabs[i]);
        }
    }

    conx.setConnectionProfile(profile);

    JDialog d = null;
    Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent);

    if (w instanceof JDialog) {
        d = new JDialog((JDialog) w, "Connection Profile", true);
    } else if (w instanceof JFrame) {
        d = new JDialog((JFrame) w, "Connection Profile", true);
    } else {
        d = new JDialog((JFrame) null, "Connection Profile", true);
    }

    final JDialog dialog = d;

    class UserAction {
        boolean connect;
    }

    final UserAction userAction = new UserAction();

    //  Create the bottom button panel
    final JButton cancel = new JButton("Cancel");
    cancel.setMnemonic('c');
    cancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            userAction.connect = false;
            dialog.setVisible(false);
        }
    });

    final JButton connect = new JButton("Connect");
    connect.setMnemonic('t');
    connect.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (conx.validateTabs()) {
                userAction.connect = true;
                dialog.setVisible(false);
            }
        }
    });
    dialog.getRootPane().setDefaultButton(connect);

    JPanel buttonPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(6, 6, 0, 0);
    gbc.weighty = 1.0;
    UIUtil.jGridBagAdd(buttonPanel, connect, gbc, GridBagConstraints.RELATIVE);
    UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER);

    JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
    southPanel.add(buttonPanel);

    //
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    mainPanel.add(conx, BorderLayout.CENTER);
    mainPanel.add(southPanel, BorderLayout.SOUTH);

    // Show the dialog
    dialog.getContentPane().setLayout(new GridLayout(1, 1));
    dialog.getContentPane().add(mainPanel);
    dialog.pack();
    dialog.setResizable(false);
    UIUtil.positionComponent(SwingConstants.CENTER, dialog);

    //show the simple box and act on the answer.
    SshToolsSimpleConnectionPrompt stscp = SshToolsSimpleConnectionPrompt.getInstance();
    StringBuffer sb = new StringBuffer();
    userAction.connect = !stscp.getHostname(sb, profile.getHost());

    boolean advanced = stscp.getAdvanced();

    if (advanced) {
        userAction.connect = false;
        profile.setHost(sb.toString());
        conx.hosttab.setConnectionProfile(profile);
        dialog.setVisible(true);
    }

    // Make sure we didn't cancel
    if (!userAction.connect) {
        return null;
    }

    conx.applyTabs();
    if (!advanced)
        profile.setHost(sb.toString());
    if (!advanced) {
        int port = DEFAULT_PORT;
        String port_S = Integer.toString(DEFAULT_PORT);
        port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S);
        try {
            port = Integer.parseInt(port_S);
        } catch (NumberFormatException e) {
            log.warn("Could not parse the port number from defaults file (property name"
                    + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ").");
        }
        profile.setPort(port);
    }
    if (!advanced)
        profile.setUsername("");

    PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_HOST, profile.getHost());
    // only save user inputed configuration
    if (advanced) {
        PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_USER, profile.getUsername());
        PreferencesStore.putInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, profile.getPort());
    }
    // Return the connection properties
    return profile;
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Make sure the data in the table is valid. This checks to make sure that for
 * all rows, all columns that contain numeric data are actually set, or none
 * of these columns are set in a row. This avoids the case of partial data.
 * This method is fail fast in that it will display a dialog box on the first
 * error it finds.//from w w  w . j a v a  2 s .co m
 * 
 * @return true if everything is ok
 */
@SuppressFBWarnings(value = "SIC_INNER_SHOULD_BE_STATIC_ANON", justification = "Static inner class to replace anonomous listener isn't worth the confusion of finding the class definition")
private boolean validateData() {
    stopCellEditors();

    final List<String> warnings = new LinkedList<String>();
    for (final ScoreCategory subjectiveCategory : getChallengeDescription().getSubjectiveCategories()) {
        final String category = subjectiveCategory.getName();
        final String categoryTitle = subjectiveCategory.getTitle();

        final List<AbstractGoal> goals = subjectiveCategory.getGoals();
        final List<Element> scoreElements = SubjectiveTableModel.getScoreElements(_scoreDocument, category);
        for (final Element scoreElement : scoreElements) {
            int numValues = 0;
            for (final AbstractGoal goal : goals) {
                final String goalName = goal.getName();

                final Element subEle = SubjectiveUtils.getSubscoreElement(scoreElement, goalName);
                if (null != subEle) {
                    final String value = subEle.getAttribute("value");
                    if (!value.isEmpty()) {
                        numValues++;
                    }
                }
            }
            if (numValues != goals.size() && numValues != 0) {
                warnings.add(categoryTitle + ": " + scoreElement.getAttribute("teamNumber")
                        + " has too few scores (needs all or none): " + numValues);
            }

        }
    }

    if (!warnings.isEmpty()) {
        // join the warnings with carriage returns and display them
        final StyledDocument doc = new DefaultStyledDocument();
        for (final String warning : warnings) {
            try {
                doc.insertString(doc.getLength(), warning + "\n", null);
            } catch (final BadLocationException ble) {
                throw new RuntimeException(ble);
            }
        }
        final JDialog dialog = new JDialog(this, "Warnings");
        final Container cpane = dialog.getContentPane();
        cpane.setLayout(new BorderLayout());
        final JButton okButton = new JButton("Ok");
        cpane.add(okButton, BorderLayout.SOUTH);
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent ae) {
                dialog.setVisible(false);
                dialog.dispose();
            }
        });
        cpane.add(new JTextPane(doc), BorderLayout.CENTER);
        dialog.pack();
        dialog.setVisible(true);
        return false;
    } else {
        return true;
    }
}

From source file:hermes.browser.HermesBrowser.java

public void showErrorDialog(final String message, final Throwable t) {
    Runnable r = new Runnable() {
        public void run() {
            String detail = null;

            if (t instanceof PyException) {
                StringBuffer s = new StringBuffer();
                PyException pyT = (PyException) t;
                pyT.traceback.dumpStack(s);

                detail = s.toString();/* ww  w  .j a  v a2s.  com*/
            } else {
                StringWriter s = new StringWriter();
                PrintWriter p = new PrintWriter(s);
                t.printStackTrace(p);
                detail = s.toString();
            }

            JideOptionPane optionPane = new JideOptionPane(message, JOptionPane.ERROR_MESSAGE,
                    JideOptionPane.CLOSE_OPTION, UIManager.getIcon("OptionPane.errorIcon"));
            optionPane.setTitle(message);

            if (detail != null) {
                optionPane.setDetails(detail);
            }
            JDialog dialog = optionPane.createDialog(HermesBrowser.this, "Error");
            dialog.setResizable(true);
            dialog.pack();
            dialog.setVisible(true);
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        r.run();
    } else {
        SwingUtilities.invokeLater(r);
    }
}

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);/*www.  j av  a  2  s.  c om*/
    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:com.att.aro.ui.view.diagnostictab.GraphPanel.java

public void launchSliderDialog(int indexKey) {
    GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendViews("StartupDelayDialog");
    IVideoPlayer player = parent.getVideoPlayer();
    double maxDuration = player.getDuration();
    if (maxDuration != -1) {
        JDialog dialog = new SliderDialogBox(this, maxDuration, chunkInfo, indexKey, vcPlot.getAllChunks());
        dialog.pack();
        dialog.setSize(dialog.getPreferredSize());
        dialog.validate();//from w w  w . j  av  a 2  s .  co m
        dialog.setModalityType(ModalityType.APPLICATION_MODAL);
        dialog.setVisible(true);
    }
}

From source file:de.cismet.verdis.CidsAppBackend.java

/**
 * DOCUMENT ME!/*from ww w  . j av  a 2s . c o m*/
 *
 * @param  locks  DOCUMENT ME!
 */
public void showObjectsLockedDialog(final Collection<CidsBean> locks) {
    final JDialog dialog = new JDialog((JFrame) null, "Gesperrte Objekte...", true);
    dialog.add(new AlreadyLockedObjectsPanel(locks));
    dialog.setResizable(false);
    dialog.pack();
    StaticSwingTools.showDialog(dialog);
}

From source file:net.mariottini.swing.JFontChooser.java

/**
 * Show a "Choose Font" dialog with the specified title and modality.
 * /*from w  w  w  .ja v  a 2s .  co m*/
 * @param parent
 *          the parent component, or null to use a default root frame as parent.
 * @param title
 *          the title for the dialog.
 * @param modal
 *          true to show a modal dialog, false to show a non-modal dialog (in this case the
 *          function will return immediately after making visible the dialog).
 * @return <code>APPROVE_OPTION</code> if the user chose a font, <code>CANCEL_OPTION</code> if the
 *         user canceled the operation. <code>CANCEL_OPTION</code> is always returned for a
 *         non-modal dialog, use an ActionListener to be notified when the user approves/cancels
 *         the dialog.
 * @see #APPROVE_OPTION
 * @see #CANCEL_OPTION
 * @see #addActionListener
 */
public int showDialog(Component parent, String title, boolean modal) {
    final int[] result = new int[] { CANCEL_OPTION };
    while (parent != null && !(parent instanceof Window)) {
        parent = parent.getParent();
    }
    final JDialog d;
    if (parent instanceof Frame) {
        d = new JDialog((Frame) parent, title, modal);
    } else if (parent instanceof Dialog) {
        d = new JDialog((Dialog) parent, title, modal);
    } else {
        d = new JDialog();
        d.setTitle(title);
        d.setModal(modal);
    }
    final ActionListener[] listener = new ActionListener[1];
    listener[0] = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals(APPROVE_SELECTION)) {
                result[0] = APPROVE_OPTION;
            }
            removeActionListener(listener[0]);
            d.setContentPane(new JPanel());
            d.setVisible(false);
            d.dispose();
        }
    };
    addActionListener(listener[0]);
    d.setComponentOrientation(getComponentOrientation());
    d.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    d.getContentPane().add(this, BorderLayout.CENTER);
    d.pack();
    d.setLocationRelativeTo(parent);
    d.setVisible(true);
    return result[0];
}