List of usage examples for javax.swing JOptionPane YES_NO_OPTION
int YES_NO_OPTION
To view the source code for javax.swing JOptionPane YES_NO_OPTION.
Click Source Link
showConfirmDialog
. From source file:Main.java
/** * Shows a simple yes/no confirmation dialog, with the "no" option selected by default. This method exists * only because there's apparently no easy way to accomplish that with JOptionPane's static helper * methods./*from w ww. j av a 2s . c om*/ * * @param parentComponent * @param message * @param title * @see JOptionPane#showConfirmDialog(Component, Object, String, int) */ public static int showConfirmDialog(Component parentComponent, Object message, String title) { String[] options = { "Yes", "No" }; return JOptionPane.showOptionDialog(parentComponent, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); }
From source file:Dialogs.java
public static boolean showYesNo(Component owner, String msg, String title) { int rc = JOptionPane.showConfirmDialog(owner, msg, title, JOptionPane.YES_NO_OPTION); return rc == JOptionPane.YES_OPTION; }
From source file:Main.java
/**Prompt the user to choose between two courses of action. @return true if the user chose the default course of action, false if the alternate course was chosen of the prompt closed.*/ public static boolean prompt2(Component parent, String question, String title, String defaultActionText, String alternateActionText) { Object[] values = new Object[] { defaultActionText, alternateActionText }; int choice = JOptionPane.showOptionDialog(parent, question, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, values, values[0]); return choice == JOptionPane.YES_OPTION; }
From source file:Main.java
public void launchDialog() { JButton findButton = new JButton("Find"); findButton.addActionListener(e -> { int start = text.getText().indexOf("is"); int end = start + "is".length(); if (start != -1) { text.requestFocus();/*w w w. j a v a 2 s .co m*/ text.select(start, end); } }); JButton cancelButton = new JButton("Cancel"); JOptionPane optionPane = new JOptionPane("Do you understand?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, new Object[] { findButton, cancelButton }); JDialog dialog = new JDialog(frame, "Click a button", false); cancelButton.addActionListener(e -> dialog.setVisible(false)); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.setLocation(100, 100); dialog.pack(); dialog.setVisible(true); }
From source file:Main.java
/** * Asks the user for confirmation.//from w w w. ja v a 2s . c o m * * @param aWindow * the parent window of the confirmation dialog; * @param aMessage * the message to display in the confirmation dialog; * @param aTitle * the title to display in the confirmation dialog. * @return <code>true</code> if the user acknowledged the confirmation, * <code>false</code> otherwise. */ public static boolean askConfirmation(final Window aWindow, final String aMessage, final String aTitle) { return JOptionPane.showConfirmDialog(aWindow, aMessage, aTitle, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION; }
From source file:br.com.pontocontrol.controleponto.ControlePonto.java
public static void solicitarLogin() { String usuario;/*from w w w.ja va 2 s . c o m*/ do { usuario = JOptionPane.showInputDialog(null, "Informe seu usurio:", "Identificao", JOptionPane.INFORMATION_MESSAGE); if (StringUtils.isBlank(usuario)) { JOptionPane.showMessageDialog(null, "Informe um login de usurio.", "Validao falhou.", JOptionPane.ERROR_MESSAGE); } } while (StringUtils.isBlank(usuario)); switch (SessaoManager.getInstance().autenticar(usuario)) { case SessaoManager.LOGIN_STATUS.OK: break; case SessaoManager.LOGIN_STATUS.USUARIO_NAO_EXISTE: int opt = JOptionPane.showConfirmDialog(null, format("O usurio com o login informado \"%s\" no existe, deseja criar um novo usurio?", usuario), "Usurio no encontrado.", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (JOptionPane.YES_OPTION == opt) { ConfiguracoesUsuario configuracoesUsuario = new ConfiguracoesUsuario(usuario); SessaoManager.getInstance().criarUsuario(configuracoesUsuario); SessaoManager.getInstance().autenticar(usuario); } break; default: break; } }
From source file:minecrunch_updater.Minecrunch_updater.java
private static void VersionCheck() throws MalformedURLException { // Get system properties String os = System.getProperty("os.name"); String home = System.getProperty("user.home"); String dir;//from ww w . ja v a2 s .c om String newfile2 = null; if (os.contains("Windows")) { dir = home + "\\.minecrunch\\"; newfile2 = dir + "\\resources\\"; } else { dir = home + "/.minecrunch/"; newfile2 = dir + "/resources/"; } try { // Get version.txt from server URL url = new URL("http://www.minecrunch.net/download/minecrunch_installer/version.txt"); File file = new File(dir + "version.txt"); File file2 = new File(newfile2 + "version.txt"); FileUtils.copyURLToFile(url, file); boolean isTwoEqual = FileUtils.contentEquals(file, file2); if (isTwoEqual) { System.out.println("Up to date."); Run(); } else { Object[] options = { "Yes, please", "No way!" }; Component frame = null; // Get answer if the user wants to update or not int n = JOptionPane.showOptionDialog(frame, "There is an update to Minecrunch Modpack.", "Would you like to update now?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { // If yes run the Update method Update(); } else { // If user chooses no then just run the minecrunch_launcher jar file Run(); } } } catch (IOException ex) { Logger.getLogger(Minecrunch_updater.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:commonline.query.gui.action.ClearDatabaseAction.java
public void actionPerformed(ActionEvent actionEvent) { if (JOptionPane.showConfirmDialog(parent, "Are you sure you want to clear the databases?", "Clear DB", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) { SwingWorker worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws Exception { for (RecordParserDataSource dataSource : dataSources) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); for (RecordLayoutTableInfo tableInfo : dataSource.getTableInfos()) { try { jdbcTemplate.execute("delete from " + tableInfo.getTableName()); } catch (Exception err) { throw new RuntimeException("Problem clearing table:" + tableInfo.getTableName() + ", in DB:" + dataSource.getUrl(), err); }/* ww w . jav a2s .co m*/ } } return null; } }; worker.execute(); } }
From source file:net.pms.newgui.Wizard.java
public static void run(final PmsConfiguration configuration) { // Total number of questions int numberOfQuestions = Platform.isMac() ? 4 : 5; // The current question number int currentQuestionNumber = 1; String status = new StringBuilder().append(Messages.getString("Wizard.2")).append(" %d ") .append(Messages.getString("Wizard.4")).append(" ").append(numberOfQuestions).toString(); Object[] okOptions = { Messages.getString("Dialog.OK") }; Object[] yesNoOptions = { Messages.getString("Dialog.YES"), Messages.getString("Dialog.NO") }; Object[] networkTypeOptions = { Messages.getString("Wizard.8"), Messages.getString("Wizard.9"), Messages.getString("Wizard.10") }; if (!Platform.isMac()) { // Ask if they want UMS to start minimized int whetherToStartMinimized = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.3"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[1]); if (whetherToStartMinimized == JOptionPane.YES_OPTION) { configuration.setMinimized(true); } else if (whetherToStartMinimized == JOptionPane.NO_OPTION) { configuration.setMinimized(false); }/*from www. j av a 2 s . c o m*/ } // Ask if their network is wired, etc. int networkType = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.7"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, networkTypeOptions, networkTypeOptions[1]); switch (networkType) { case JOptionPane.YES_OPTION: // Wired (Gigabit) configuration.setMaximumBitrate("0"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.NO_OPTION: // Wired (100 Megabit) configuration.setMaximumBitrate("90"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.CANCEL_OPTION: // Wireless configuration.setMaximumBitrate("30"); configuration.setMPEG2MainSettings("Automatic (Wireless)"); configuration.setx264ConstantRateFactor("Automatic (Wireless)"); break; default: break; } // Ask if they want to hide advanced options int whetherToHideAdvancedOptions = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.11"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToHideAdvancedOptions == JOptionPane.YES_OPTION) { configuration.setHideAdvancedOptions(true); } else if (whetherToHideAdvancedOptions == JOptionPane.NO_OPTION) { configuration.setHideAdvancedOptions(false); } // Ask if they want to scan shared folders int whetherToScanSharedFolders = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.IsStartupScan"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToScanSharedFolders == JOptionPane.YES_OPTION) { configuration.setScanSharedFoldersOnStartup(true); } else if (whetherToScanSharedFolders == JOptionPane.NO_OPTION) { configuration.setScanSharedFoldersOnStartup(false); } // Ask to set at least one shared folder JOptionPane.showOptionDialog(null, Messages.getString("Wizard.12"), String.format(status, currentQuestionNumber++), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, okOptions, okOptions[0]); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { JFileChooser chooser; try { chooser = new JFileChooser(); } catch (Exception ee) { chooser = new JFileChooser(new RestrictedFileSystemView()); } chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle(Messages.getString("Wizard.12")); chooser.setMultiSelectionEnabled(false); if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { configuration.setOnlySharedDirectory(chooser.getSelectedFile().getAbsolutePath()); } else { // If the user cancels this option, the default directories will be used. } } }); } catch (InterruptedException | InvocationTargetException e) { LOGGER.error("Error when saving folders: ", e); } // The wizard finished, do not ask them again configuration.setRunWizard(false); // Save all changes try { configuration.save(); } catch (ConfigurationException e) { LOGGER.error("Error when saving changed configuration: ", e); } }
From source file:com.raphfrk.craftproxyclient.gui.GUIManager.java
public static JSONObject getPreviousLoginDetails() { JSONObject loginInfo = AuthManager.refreshAccessToken(); if (loginInfo == null) { return null; }/*from ww w.ja v a 2s. c o m*/ final AtomicInteger option = new AtomicInteger(); Runnable r = new Runnable() { public void run() { option.set(JOptionPane.showConfirmDialog(CraftProxyClient.getGUI(), "Login as " + AuthManager.getUsername() + "?", "Login", JOptionPane.YES_NO_OPTION)); } }; if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException | InterruptedException e) { return null; } } if (option.get() == 0) { return loginInfo; } else { return null; } }