List of usage examples for javax.swing JDialog getSize
public Dimension getSize()
From source file:org.executequery.gui.browser.SSHTunnelConnectionPanel.java
public boolean canConnect() { if (useSshCheckbox.isSelected()) { if (!hasValue(userNameField)) { GUIUtilities// w w w . j a v a2 s . c om .displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH user name"); return false; } if (!hasValue(portField)) { GUIUtilities.displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH port"); return false; } if (!hasValue(passwordField)) { final JPasswordField field = WidgetFactory.createPasswordField(); JOptionPane optionPane = new JOptionPane(field, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = optionPane.createDialog("Enter SSH password"); dialog.addWindowFocusListener(new WindowAdapter() { @Override public void windowGainedFocus(WindowEvent e) { field.requestFocusInWindow(); } }); dialog.pack(); dialog.setLocation(GUIUtilities.getLocationForDialog(dialog.getSize())); dialog.setVisible(true); dialog.dispose(); int result = Integer.parseInt(optionPane.getValue().toString()); if (result == JOptionPane.OK_OPTION) { String password = MiscUtils.charsToString(field.getPassword()); if (StringUtils.isNotBlank(password)) { passwordField.setText(password); return true; } else { GUIUtilities.displayErrorMessage( "You have selected SSH Tunnel but have not provided an SSH password"); // send back here and force them to select cancel if they want to bail return canConnect(); } } return false; } } return true; }
From source file:org.languagetool.gui.Tools.java
/** * Set dialog location to the center of the screen * * @param dialog the dialog which will be centered * @since 2.6//from w ww . j a v a 2 s. c om */ public static void centerDialog(JDialog dialog) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = dialog.getSize(); dialog.setLocation(screenSize.width / 2 - frameSize.width / 2, screenSize.height / 2 - frameSize.height / 2); dialog.setLocationByPlatform(true); }
From source file:pl.otros.vfs.browser.JOtrosVfsBrowserDialog.java
public ReturnValue showOpenDialog(Component parent, String title) { JDialog dialog = createDialog(parent); dialog.setTitle(title);/*from w w w . j ava2s. c o m*/ if (size == null) { dialog.pack(); } else { dialog.setSize(size); } dialog.setVisible(true); size = dialog.getSize(); return returnValue; }