List of usage examples for javax.swing JOptionPane CLOSED_OPTION
int CLOSED_OPTION
To view the source code for javax.swing JOptionPane CLOSED_OPTION.
Click Source Link
CANCEL_OPTION
or NO_OPTION
. From source file:Main.java
/** Show a confirmation message box with line wrapped message. * * 'optionType' is one of the JOptionPane.XXX_OPTION combination * constants, and the return value is one of the single-value * constants. *//*from w ww. j a v a2s . c o m*/ public static int confirmationBox(Component parent, String message, String title, int optionType) { JOptionPane pane = makeWordWrapJOptionPane(); pane.setMessage(message); pane.setMessageType(JOptionPane.QUESTION_MESSAGE); pane.setOptionType(optionType); JDialog dialog = pane.createDialog(parent, title); dialog.setVisible(true); Object result = pane.getValue(); if (result == null || !(result instanceof Integer)) { return JOptionPane.CLOSED_OPTION; } else { return ((Integer) result).intValue(); } }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(new JLabel("Placeholder label")); pack();// ww w . ja v a2 s . c o m setSize(200, 200); setVisible(true); int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?"); String result = "?"; switch (replaced) { case JOptionPane.CANCEL_OPTION: result = "Canceled"; break; case JOptionPane.CLOSED_OPTION: result = "Closed"; break; case JOptionPane.NO_OPTION: result = "No"; break; case JOptionPane.YES_OPTION: result = "Yes"; break; default: ; } System.out.println("Replace? " + result); }
From source file:Test.java
public Test() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(new JLabel("Placeholder label")); pack();// w w w. j av a 2s. c o m setSize(200, 200); setVisible(true); int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?"); String result = "?"; switch (replaced) { case JOptionPane.CANCEL_OPTION: result = "Canceled"; break; case JOptionPane.CLOSED_OPTION: result = "Closed"; break; case JOptionPane.NO_OPTION: result = "No"; break; case JOptionPane.YES_OPTION: result = "Yes"; break; default: ; } System.out.println("Replace? " + result); }
From source file:edu.ku.brc.specify.conversion.SpecifyDBConverter.java
/** * @param args//from www. jav a 2 s .c om * @throws Exception */ public static void main(String args[]) throws Exception { /*try { List<String> list = FileUtils.readLines(new File("/Users/rods/drop.sql")); Vector<String> list2 = new Vector<String>(); for (String line : list) { list2.add(line+";"); } FileUtils.writeLines(new File("/Users/rods/drop2.sql"), list2); return; } catch (Exception ex) { ex.printStackTrace(); }*/ // Set App Name, MUST be done very first thing! UIRegistry.setAppName("Specify"); //$NON-NLS-1$ log.debug("********* Current [" + (new File(".").getAbsolutePath()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ UIRegistry.setEmbeddedDBPath(UIRegistry.getDefaultEmbeddedDBPath()); // on the local machine AppBase.processArgs(args); final SpecifyDBConverter converter = new SpecifyDBConverter(); Logger logger = LogManager.getLogger("edu.ku.brc"); if (logger != null) { logger.setLevel(Level.ALL); System.out.println("Setting " + logger.getName() + " to " + logger.getLevel()); } logger = LogManager.getLogger(edu.ku.brc.dbsupport.HibernateUtil.class); if (logger != null) { logger.setLevel(Level.INFO); System.out.println("Setting " + logger.getName() + " to " + logger.getLevel()); } // Create Specify Application SwingUtilities.invokeLater(new Runnable() { public void run() { try { if (!System.getProperty("os.name").equals("Mac OS X")) { UIManager.setLookAndFeel(new Plastic3DLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new DesertBlue()); } } catch (Exception e) { log.error("Can't change L&F: ", e); } Pair<String, String> namePair = null; try { if (converter.selectedDBsToConvert(false)) { namePair = converter.chooseTable("Select a DB to Convert", "Specify 5 Databases", true); } } catch (SQLException ex) { ex.printStackTrace(); JOptionPane.showConfirmDialog(null, "The Converter was unable to login.", "Error", JOptionPane.CLOSED_OPTION); } if (namePair != null) { frame = new ProgressFrame("Converting"); converter.processDB(); } else { JOptionPane.showConfirmDialog(null, "The Converter was unable to login.", "Error", JOptionPane.CLOSED_OPTION); System.exit(0); } } }); }
From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java
public static DialogResult showConfirmationDialog(Component parent, String title, String message) { final Object[] options = { "Yes", "No", "Cancel" }; final int outcome = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); switch (outcome) { case 0:/*from www . j a va 2 s .c o m*/ return DialogResult.YES; case 1: return DialogResult.NO; case 2: case JOptionPane.CLOSED_OPTION: return DialogResult.CANCEL; default: throw new RuntimeException("Internal error, unexpected outcome " + outcome); } }
From source file:net.menthor.editor.v2.util.Util.java
public static JFileChooser createChooser(String lastPath, final boolean checkOverrideFile) { return new JFileChooser(lastPath) { private static final long serialVersionUID = 1L; @Override/*from www.j av a2s .c om*/ public void approveSelection() { File f = getSelectedFile(); if (f.exists() && checkOverrideFile) { int result = JOptionPane.showConfirmDialog(this, "\"" + f.getName() + "\" already exists. Do you want to overwrite it?", "Existing file", JOptionPane.YES_NO_CANCEL_OPTION); switch (result) { case JOptionPane.YES_OPTION: super.approveSelection(); return; case JOptionPane.NO_OPTION: return; case JOptionPane.CLOSED_OPTION: return; case JOptionPane.CANCEL_OPTION: cancelSelection(); return; } } super.approveSelection(); } }; }
From source file:com.sun.jersey.client.apache.config.DefaultCredentialsProvider.java
public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (scheme == null) { return null; }// w w w . ja va 2s . c o m try { JTextField userField = new JTextField(); JPasswordField passwordField = new JPasswordField(); int response; if (scheme instanceof NTLMScheme) { JTextField domainField = new JTextField(); Object[] msg = { host + ":" + port + " requires Windows authentication", "Domain", domainField, "User Name", userField, "Password", passwordField }; response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION); if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) { throw new CredentialsNotAvailableException("User cancled windows authentication."); } return new NTCredentials(userField.getText(), new String(passwordField.getPassword()), host, domainField.getText()); } else if (scheme instanceof RFC2617Scheme) { Object[] msg = { host + ":" + port + " requires authentication with the realm '" + scheme.getRealm() + "'", "User Name", userField, "Password", passwordField }; response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION); if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) { throw new CredentialsNotAvailableException("User cancled windows authentication."); } return new UsernamePasswordCredentials(userField.getText(), new String(passwordField.getPassword())); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + scheme.getSchemeName()); } } catch (IOException ioe) { throw new CredentialsNotAvailableException(ioe.getMessage(), ioe); } }
From source file:components.CustomDialog.java
/** Creates the reusable dialog. */ public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) { super(aFrame, true); dd = parent;// w w w.j a v a2 s. c o m magicWord = aWord.toUpperCase(); setTitle("Quiz"); textField = new JTextField(10); //Create an array of the text and components to be displayed. String msgString1 = "What was Dr. SEUSS's real last name?"; String msgString2 = "(The answer is \"" + magicWord + "\".)"; Object[] array = { msgString1, msgString2, textField }; //Create an array specifying the number of dialog buttons //and their text. Object[] options = { btnString1, btnString2 }; //Create the JOptionPane. optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]); //Make this dialog display it. setContentPane(optionPane); //Handle window closing correctly. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { /* * Instead of directly closing the window, * we're going to change the JOptionPane's * value property. */ optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION)); } }); //Ensure the text field always gets the first focus. addComponentListener(new ComponentAdapter() { public void componentShown(ComponentEvent ce) { textField.requestFocusInWindow(); } }); //Register an event handler that puts the text into the option pane. textField.addActionListener(this); //Register an event handler that reacts to option pane state changes. optionPane.addPropertyChangeListener(this); }
From source file:OptPaneComparison.java
protected String getOptionPaneValue() { // Get the result . . . Object o = optPane.getInputValue(); String s = "<Unknown>"; if (o != null) s = (String) o;// w w w . j a va2s . c o m Object val = optPane.getValue(); // which button? // Check for cancel button or closed option if (val != null) { if (val instanceof Integer) { int intVal = ((Integer) val).intValue(); if ((intVal == JOptionPane.CANCEL_OPTION) || (intVal == JOptionPane.CLOSED_OPTION)) s = "<Cancel>"; } } // A little trick to clean the text field. It is only updated if // the initial value gets changed. To do this, we'll set it to a // dummy value ("X") and then clear it. optPane.setValue(""); optPane.setInitialValue("X"); optPane.setInitialValue(""); return s; }
From source file:br.com.elotech.sits.config.form.ConfigForm.java
private void save() { Properties config = new Properties(loadConfigFile()); config.setProperty("ISS.serviceType", "elotech"); try {/* w ww. ja va 2 s . c om*/ saveFields(config); saveKeyAlias(config); config.store(new FileOutputStream(new File(CONFIG_FILE)), "Arquivo gerado pelo configurador"); close(); } catch (Exception e) { LogFactory.getLog(getClass()).error(e.getLocalizedMessage(), e); JOptionPane.showMessageDialog(getFrame(), e.getLocalizedMessage(), "Erro durante gravao", JOptionPane.CLOSED_OPTION + JOptionPane.ERROR_MESSAGE); } }