List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE
int QUESTION_MESSAGE
To view the source code for javax.swing JOptionPane QUESTION_MESSAGE.
Click Source Link
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 w w .j a v a2 s . co m*/ 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:OptPaneComparison.java
public OptPaneComparison(final String message) { setDefaultCloseOperation(EXIT_ON_CLOSE); final int msgType = JOptionPane.QUESTION_MESSAGE; final int optType = JOptionPane.OK_CANCEL_OPTION; final String title = message; setSize(350, 200);/*from w w w. j a v a 2 s .c o m*/ // Create a desktop for internal frames final JDesktopPane desk = new JDesktopPane(); setContentPane(desk); // Add a simple menu bar JMenuBar mb = new JMenuBar(); setJMenuBar(mb); JMenu menu = new JMenu("Dialog"); JMenu imenu = new JMenu("Internal"); mb.add(menu); mb.add(imenu); final JMenuItem construct = new JMenuItem("Constructor"); final JMenuItem stat = new JMenuItem("Static Method"); final JMenuItem iconstruct = new JMenuItem("Constructor"); final JMenuItem istat = new JMenuItem("Static Method"); menu.add(construct); menu.add(stat); imenu.add(iconstruct); imenu.add(istat); // Create our JOptionPane. We're asking for input, so we call // setWantsInput. // Note that we cannot specify this via constructor parameters. optPane = new JOptionPane(message, msgType, optType); optPane.setWantsInput(true); // Add a listener for each menu item that will display the appropriate // dialog/internal frame construct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JDialog d = optPane.createDialog(desk, title); d.setVisible(true); respond(getOptionPaneValue()); } }); stat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInputDialog(desk, message, title, msgType); respond(s); } }); iconstruct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JInternalFrame f = optPane.createInternalFrame(desk, title); f.setVisible(true); // Listen for the frame to close before getting the value from // it. f.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent ev) { if ((ev.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) && (ev.getNewValue() == Boolean.TRUE)) { respond(getOptionPaneValue()); } } }); } }); istat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInternalInputDialog(desk, message, title, msgType); respond(s); } }); }
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 w w w . j av a2 s . c o m 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:oct.util.Util.java
public static OCT getOCT(BufferedImage octImage, OCTAnalysisUI octAnalysisUI, String octFileName) { boolean exit = false; //ask the user for the x-scale double xscale = 0; do {/* w w w. ja v a2 s . c om*/ String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT X-axis scale (microns per pixel):", "X-Scale input", JOptionPane.QUESTION_MESSAGE); if (!(res == null || res.isEmpty())) { xscale = Util.parseNumberFromInput(res); } if (res == null || res.isEmpty() || xscale <= 0) { exit = JOptionPane.showConfirmDialog(octAnalysisUI, "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.", "Input Error", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION; } } while (!exit && xscale <= 0); if (exit) { return null; } //ask the user for the y-scale double yscale = 0; do { String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT Y-axis scale (microns per pixel):", "Y-Scale input", JOptionPane.QUESTION_MESSAGE); if (!(res == null || res.isEmpty())) { yscale = Util.parseNumberFromInput(res); } if (res == null || res.isEmpty() || yscale <= 0) { exit = JOptionPane.showConfirmDialog(octAnalysisUI, "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.", "Input Error", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION; } } while (!exit && yscale <= 0); if (exit) { return null; } //store values and return OCT object OCTAnalysisManager octMngr = OCTAnalysisManager.getInstance(); octMngr.setXscale(xscale); octMngr.setYscale(yscale); return new OCT(octImage, octFileName); }
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 w w w . j a va2 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:net.fabricmc.installer.installer.MultiMCInstaller.java
public static void install(File mcDir, String version, IInstallerProgress progress) throws Exception { File instancesDir = new File(mcDir, "instances"); if (!instancesDir.exists()) { throw new FileNotFoundException(Translator.getString("install.multimc.notFound")); }// www.j a va 2s. com progress.updateProgress(Translator.getString("install.multimc.findInstances"), 10); String mcVer = version.split("-")[0]; List<File> validInstances = new ArrayList<>(); for (File instanceDir : instancesDir.listFiles()) { if (instanceDir.isDirectory()) { if (isValidInstance(instanceDir, mcVer)) { validInstances.add(instanceDir); } } } if (validInstances.isEmpty()) { throw new Exception(Translator.getString("install.multimc.noInstances").replace("[MCVER]", mcVer)); } List<String> instanceNames = new ArrayList<>(); for (File instance : validInstances) { instanceNames.add(instance.getName()); } String instanceName = (String) JOptionPane.showInputDialog(null, Translator.getString("install.multimc.selectInstance"), Translator.getString("install.multimc.selectInstance"), JOptionPane.QUESTION_MESSAGE, null, instanceNames.toArray(), instanceNames.get(0)); if (instanceName == null) { progress.updateProgress(Translator.getString("install.multimc.canceled"), 100); return; } progress.updateProgress( Translator.getString("install.multimc.installingInto").replace("[NAME]", instanceName), 25); File instnaceDir = null; for (File instance : validInstances) { if (instance.getName().equals(instanceName)) { instnaceDir = instance; } } if (instnaceDir == null) { throw new FileNotFoundException("Could not find " + instanceName); } File patchesDir = new File(instnaceDir, "patches"); if (!patchesDir.exists()) { patchesDir.mkdir(); } File fabricJar = new File(patchesDir, "Fabric-" + version + ".jar"); if (!fabricJar.exists()) { progress.updateProgress(Translator.getString("install.client.downloadFabric"), 30); FileUtils.copyURLToFile(new URL("http://maven.modmuss50.me/net/fabricmc/fabric-base/" + version + "/fabric-base-" + version + ".jar"), fabricJar); } progress.updateProgress(Translator.getString("install.multimc.createJson"), 70); File fabricJson = new File(patchesDir, "fabric.json"); if (fabricJson.exists()) { fabricJson.delete(); } String json = readBaseJson(); json = json.replaceAll("%VERSION%", version); ZipFile fabricZip = new ZipFile(fabricJar); ZipEntry dependenciesEntry = fabricZip.getEntry("dependencies.json"); String fabricDeps = IOUtils.toString(fabricZip.getInputStream(dependenciesEntry), Charset.defaultCharset()); json = json.replace("%DEPS%", stripDepsJson(fabricDeps.replace("\n", ""))); FileUtils.writeStringToFile(fabricJson, json, Charset.defaultCharset()); fabricZip.close(); progress.updateProgress(Translator.getString("install.success"), 100); }
From source file:au.org.ala.delta.ui.MessageDialogHelper.java
/** * Uses JOptionPane.showInputDialog to display the supplied (multi-line) message and return the * user selection.//from www.java 2 s . c om * @param parent the parent component used to display the JOptionPane. * @param title the title for the option pane. * @param text the message text to display on the option pane. Multi-line messages should * use the "\n" character. * @param numColumns the column position to wrap the text at. * @return the value returned from the JOptionPane showConfirmDialog method (i.e the user selection) */ public static int showConfirmDialog(Component parent, String title, String text, int numColumns) { JTextArea messageDisplay = createMessageDisplay(text, numColumns); return JOptionPane.showConfirmDialog(parent, messageDisplay, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); }
From source file:net.itransformers.topologyviewer.menu.handlers.graphTools.searchMenuHandlers.SearchByIpMenuHandler.java
@Override public void actionPerformed(ActionEvent e) { // Map<String, Map<String, GraphMLMetadata<G>>> test1 = graphmlLoader(); // String key = JOptionPane.showInputDialog(frame, "Choose IP", JOptionPane.QUESTION_MESSAGE); final String ip = JOptionPane.showInputDialog(frame, "Enter IP", "Value", JOptionPane.QUESTION_MESSAGE); GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent(); Set<String> foundVertexes; foundVertexes = viewerPanel.FindNodeByKey("RoutePrefixes", new Object() { @Override/* w w w . j a v a 2s. co m*/ public boolean equals(Object obj) { String s = (String) obj; String[] ipRanges = s.split(","); for (String ipRangeNotTrimmed : ipRanges) { String ipRange = ipRangeNotTrimmed.trim(); if (ipRange.equals("") || ipRange.equals("0.0.0.0/0")) continue; try { SubnetUtils subnet = new SubnetUtils(ipRange); if (subnet.getInfo().isInRange(ip)) { return true; } } catch (IllegalArgumentException iae) { logger.error("Can not parse ip or ip range:" + ipRange + ", ip:" + ip); System.out.println("Can not parse ip or ip range:" + ipRange + ", ip:" + ip); iae.printStackTrace(); continue; } } return false; } }); if (!foundVertexes.isEmpty()) { Iterator it = foundVertexes.iterator(); if (foundVertexes.size() == 1) { Object element = it.next(); System.out.println("Redrawing around " + element.toString()); viewerPanel.SetPickedState(element.toString()); viewerPanel.Animator(element.toString()); } else { JOptionPane.showMessageDialog(frame, "Multiple Nodes with ip " + ip + " found :\n" + foundVertexes, "Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(frame, "Can not find node with ip " + ip, "Error", JOptionPane.ERROR_MESSAGE); } }
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/*from ww w. j ava 2 s .c om*/ 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:groovesquid.UpdateCheckThread.java
@Override public void run() { UpdateCheck updateCheck = gson.fromJson(getFile(updateFile), UpdateCheck.class); if (updateCheck.getClients() != null) Grooveshark.setClients(updateCheck.getClients()); if (Utils.compareVersions(updateCheck.getVersion(), Main.getVersion()) > 0) { if (JOptionPane.showConfirmDialog(null, "New version (v" + updateCheck.getVersion() + ") is available! Do you want to download the new version (recommended)?", "New version", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) { try { Desktop.getDesktop().browse(java.net.URI.create("http://groovesquid.com/#download")); } catch (IOException ex) { log.log(Level.SEVERE, null, ex); }/* w ww. j av a 2 s . com*/ } } }