Java Code Examples for javax.swing.JOptionPane#DEFAULT_OPTION
The following examples show how to use
javax.swing.JOptionPane#DEFAULT_OPTION .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingClientApplication.java From chipster with MIT License | 6 votes |
/** * Check if there are uploading jobs and ask if user wants to kill * them. Returns true if the jobs were killed or there weren't any. Returns * false if the killing was cancelled. * * @return false if the action was cancelled */ private boolean killUploadingTasks() { // Check the running tasks int returnValue = JOptionPane.DEFAULT_OPTION; if (taskExecutor.getUploadingTaskCount() > 0) { String message = ""; if (taskExecutor.getUploadingTaskCount() == 1) { message += "There is a task uploading input files. Are you sure you want to cancel the task?"; } else { message += "There are " + taskExecutor.getUploadingTaskCount() + " tasks uploading input files. " + "Are you sure you want to cancel these tasks?"; } Object[] options = { "Cancel uploading tasks", "Continue uploading" }; returnValue = JOptionPane.showOptionDialog(this.getMainFrame(), message, "Confirm close", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (returnValue == JOptionPane.YES_OPTION) { taskExecutor.killUploadingTasks(); } else { return false; } } return true; }
Example 2
Source File: OurDialog.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Helper method for constructing an always-on-top modal dialog. */ private static Object show(JFrame parent, String title, int type, Object message, Object[] options, Object initialOption) { if (options == null) { options = new Object[] { "Ok" }; initialOption = "Ok"; } JOptionPane p = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, options, initialOption); p.setInitialValue(initialOption); JDialog d = p.createDialog(parent, title); p.selectInitialValue(); d.setAlwaysOnTop(true); d.setVisible(true); d.dispose(); return p.getValue(); }
Example 3
Source File: DesktopGDXProgressDialog.java From gdx-dialogs with Apache License 2.0 | 6 votes |
@Override public GDXProgressDialog build() { optionPane = new JOptionPane(message, JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] {}, null); dialog = new JDialog(); dialog.setTitle((String) title); dialog.setModal(true); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.pack(); return this; }
Example 4
Source File: LoadingWindow.java From jmg with GNU General Public License v2.0 | 6 votes |
public static void showLoadingWindow() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } JOptionPane pane = new JOptionPane("Загрузка. Пожалуйста, подождите...", JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[]{}, null); LOADING_PANE = new JDialog(); LOADING_PANE.setModal(false); LOADING_PANE.setContentPane(pane); LOADING_PANE.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); LOADING_PANE.setLocation(100, 200); LOADING_PANE.pack(); LOADING_PANE.setVisible(true); }
Example 5
Source File: ConfirmTabCloseDialog.java From tn5250j with GNU General Public License v2.0 | 6 votes |
private void initLayout() { Object[] messages = new Object[1]; { JPanel srp = new JPanel(); srp.setLayout(new BorderLayout()); JLabel jl = new JLabel("Are you sure you want to close this tab?"); srp.add(jl, BorderLayout.NORTH); messages[0] = srp; } pane = new JOptionPane(messages, // the dialog message array JOptionPane.QUESTION_MESSAGE, // message type JOptionPane.DEFAULT_OPTION, // option type null, // optional icon, use null to use the default icon OPTIONS, // options string array, will be made into buttons OPTIONS[0]); dialog = pane.createDialog(parent, LangTool.getString("sa.confirmTabClose")); }
Example 6
Source File: ScrMainMenu.java From PolyGlot with MIT License | 6 votes |
/** * Gives user option to save file, returns continue/don't continue * * @return true to signal continue, false to signal stop */ public boolean saveOrCancelTest() { boolean ret = true; if (core != null && !core.isLanguageEmpty()) { int saveFirst = InfoBox.yesNoCancel("Save First?", "Save current language before performing action?", core.getRootWindow()); if (saveFirst == JOptionPane.YES_OPTION) { boolean saved = saveFile(); // if the file didn't save (usually due to a last minute cancel) don't continue. if (!saved) { ret = false; } } else if (saveFirst == JOptionPane.CANCEL_OPTION || saveFirst == JOptionPane.DEFAULT_OPTION) { ret = false; } } return ret; }
Example 7
Source File: OptionDialog.java From Astrosoft with GNU General Public License v2.0 | 5 votes |
public static int showDialog(String message, int messageType){ int optionType = JOptionPane.DEFAULT_OPTION; String title = null; if (messageType == JOptionPane.ERROR_MESSAGE){ title = "Error "; optionType = JOptionPane.DEFAULT_OPTION; }else if (messageType == JOptionPane.QUESTION_MESSAGE){ title = "Confirm "; optionType = JOptionPane.YES_NO_OPTION; } else if (messageType == JOptionPane.INFORMATION_MESSAGE){ title = "Information "; optionType = JOptionPane.DEFAULT_OPTION; } JOptionPane pane = new JOptionPane(message, messageType, optionType); JDialog dialog = pane.createDialog(pane, title); UIUtil.applyOptionPaneBackground(pane,UIConsts.OPTIONPANE_BACKGROUND); dialog.setVisible(true); Object selectedValue = pane.getValue(); if(selectedValue instanceof Integer) { return ((Integer)selectedValue).intValue(); } return JOptionPane.CLOSED_OPTION; }
Example 8
Source File: DialogDisplayerImplTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { LOG = Logger.getLogger("test." + getName()); dd = new DialogDisplayerImpl (RESULT); closeOwner = new JButton ("Close this dialog"); childDD = new DialogDescriptor ("Child", "Child", false, null); openChild = new JButton ("Open child"); closeChild = new JButton ("Close child"); pane = new JOptionPane ("", JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] {openChild, closeChild}); }
Example 9
Source File: Messages.java From jclic with GNU General Public License v2.0 | 5 votes |
public int showErrorWarning(Component parent, String key, List<Object> values, Exception ex, String buttons) { if (key == null) { key = ERROR; } List<Object> v = new ArrayList<Object>(); String mainMsg = get(key); System.err.println(mainMsg); v.add(mainMsg); if (values != null) { Iterator it = values.iterator(); while (it.hasNext()) { Object o = it.next(); if (o != null) { v.add(o); System.err.println(o); } } } if (ex != null) { String s = ex.getLocalizedMessage(); if (s != null) { v.add(s); } else { v.add(ex.toString()); } System.err.println(s); ex.printStackTrace(System.err); } NarrowOptionPane pane = new NarrowOptionPane(60, v.toArray(), JOptionPane.ERROR_MESSAGE, JOptionPane.DEFAULT_OPTION, null, parseButtons(buttons)); return getFeedback(parent, pane, get(ERROR)); }
Example 10
Source File: Messages.java From jclic with GNU General Public License v2.0 | 5 votes |
public void showAlert(Component parent, String[] msg) { System.err.println("Warning:"); for (String s : msg) { System.err.println(s); } NarrowOptionPane pane = new NarrowOptionPane(60, msg, JOptionPane.WARNING_MESSAGE, JOptionPane.DEFAULT_OPTION, null, parseButtons(null)); getFeedback(parent, pane, get(WARNING)); }
Example 11
Source File: SystemRequestDialog.java From tn5250j with GNU General Public License v2.0 | 5 votes |
private void initLayout() { JPanel srp = new JPanel(); srp.setLayout(new BorderLayout()); JLabel jl = new JLabel("Enter alternate job"); text = new JTextField(); srp.add(jl, BorderLayout.NORTH); srp.add(text, BorderLayout.CENTER); Object[] message = new Object[1]; message[0] = srp; pane = new JOptionPane(message, // the dialog message array JOptionPane.QUESTION_MESSAGE, // message type JOptionPane.DEFAULT_OPTION, // option type null, // optional icon, use null to use the default icon OPTIONS, // options string array, will be made into buttons OPTIONS[0]); dialog = pane.createDialog(parent, "System Request"); // add the listener that will set the focus to the desired option dialog.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { text.requestFocus(); } }); }
Example 12
Source File: OurDialog.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Popup the given informative message, then ask the user to click Close to * close it. */ public static void showmsg(String title, Object... msg) { JButton dismiss = new JButton(Util.onMac() ? "Dismiss" : "Close"); Object[] objs = new Object[msg.length + 1]; System.arraycopy(msg, 0, objs, 0, msg.length); objs[objs.length - 1] = OurUtil.makeH(null, dismiss, null); JOptionPane about = new JOptionPane(objs, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] {}); JDialog dialog = about.createDialog(null, title); dismiss.addActionListener(Runner.createDispose(dialog)); dialog.setAlwaysOnTop(true); dialog.setVisible(true); dialog.dispose(); }
Example 13
Source File: VizController.java From ontopia with Apache License 2.0 | 4 votes |
private TopicMapIF importTopicMap(TopicMapReaderIF reader, String name) { final JOptionPane pane = new JOptionPane(new Object[] { Messages .getString("Viz.LoadingTopicMap") + name }, JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new String[] {}, null); Frame frame = JOptionPane.getFrameForComponent(vpanel); final JDialog dialog = new JDialog(frame, Messages .getString("Viz.Information"), true); dialog.setContentPane(pane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { JOptionPane .showMessageDialog(pane, Messages.getString("Viz.CannotCancelOperation"), Messages.getString("Viz.Information"), JOptionPane.INFORMATION_MESSAGE); } }); dialog.pack(); dialog.setLocationRelativeTo(frame); TopicMapIF tm; final TopicMapReaderIF r = reader; final SwingWorker worker = new SwingWorker() { @Override public Object construct() { TopicMapIF result = null; try { result = r.read(); } catch (IOException e) { dialog.setVisible(false); ErrorDialog.showError(vpanel, e.getMessage()); } return result; } @Override public void finished() { dialog.setVisible(false); } }; worker.start(); dialog.setVisible(true); tm = (TopicMapIF) worker.getValue(); return tm; }
Example 14
Source File: SelectExportMethodDialog.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private static DialogDescriptor createDialog(Component parentComponent, String title, String text, String helpID, JCheckBox[] options) { final String copyToClipboardText = "Copy to Clipboard"; /*I18N*/ final String writeToFileText = "Write to File"; /*I18N*/ final String cancelText = "Cancel"; /*I18N*/ final String iconDir = "/org/esa/snap/resources/images/icons/"; final ImageIcon copyIcon = new ImageIcon(SelectExportMethodDialog.class.getResource(iconDir + "Copy16.gif")); final ImageIcon saveIcon = new ImageIcon(SelectExportMethodDialog.class.getResource(iconDir + "Save16.gif")); final JButton copyToClipboardButton = new JButton(copyToClipboardText); copyToClipboardButton.setMnemonic('b'); copyToClipboardButton.setIcon(copyIcon); final JButton writeToFileButton = new JButton(writeToFileText); writeToFileButton.setMnemonic('W'); writeToFileButton.setIcon(saveIcon); final JButton cancelButton = new JButton(cancelText); cancelButton.setMnemonic('C'); cancelButton.setIcon(null); final JPanel panel = new JPanel(new GridBagLayout()); final JPanel checkboxPanel = new JPanel(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.LINE_START; c.gridx = 0; c.gridy = GridBagConstraints.RELATIVE; for (JCheckBox option : options) { checkboxPanel.add(option, c); } c.gridx = 0; c.gridy = 0; panel.add(checkboxPanel, c); final JPanel buttonPanel = new JPanel(new FlowLayout()); c.gridy = GridBagConstraints.RELATIVE; buttonPanel.add(copyToClipboardButton, c); buttonPanel.add(writeToFileButton, c); buttonPanel.add(cancelButton, c); c.gridx = 0; c.gridy = 1; panel.add(buttonPanel, c); final JOptionPane optionPane = new JOptionPane(text, /*I18N*/ JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new JPanel[]{panel}, copyToClipboardButton); final JDialog dialog = optionPane.createDialog(parentComponent, title); dialog.getContentPane().setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS)); if (helpID != null) { HelpCtx.setHelpIDString((JComponent) optionPane, helpID); } // Create action listener for all 3 buttons (as instance of an anonymous class) final ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { optionPane.setValue(e.getSource()); dialog.setVisible(false); dialog.dispose(); } }; copyToClipboardButton.addActionListener(actionListener); writeToFileButton.addActionListener(actionListener); cancelButton.addActionListener(actionListener); return new DialogDescriptor(dialog, optionPane, copyToClipboardButton, writeToFileButton); }
Example 15
Source File: NarrowOptionPane.java From jclic with GNU General Public License v2.0 | 4 votes |
public NarrowOptionPane(int maxCharactersPerLineCount, Object message, int messageType) { this(maxCharactersPerLineCount, message, messageType, JOptionPane.DEFAULT_OPTION); }
Example 16
Source File: Messages.java From jclic with GNU General Public License v2.0 | 4 votes |
public int showQuestionDlgObj(Component parent, Object msg, String titleKey, String buttons) { NarrowOptionPane pane = new NarrowOptionPane(60, msg, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, parseButtons(buttons)); String title = get(StrUtils.secureString(titleKey, "QUESTION")); return getFeedback(parent, pane, title); }
Example 17
Source File: SwingClientApplication.java From chipster with MIT License | 4 votes |
private void continueSaveSession(JFileChooser fileChooser, boolean remote) { try { int ret = fileChooser.showSaveDialog(this.getMainFrame()); // if was approved, then save it if (ret == JFileChooser.APPROVE_OPTION) { try { final File file; boolean exists; if (remote) { // use filename as it is (remote sessions use more human readable names) file = fileChooser.getSelectedFile(); exists = false; @SuppressWarnings("unchecked") List<DbSession> sessions = (List<DbSession>)fileChooser.getClientProperty("sessions"); for (DbSession session : sessions) { if (file.getName().equals(session.getName())) { exists = true; break; } } } else { // add extension if needed file = fileChooser.getSelectedFile().getName().endsWith("." + UserSession.SESSION_FILE_EXTENSION) ? fileChooser.getSelectedFile() : new File(fileChooser.getSelectedFile().getCanonicalPath() + "." + UserSession.SESSION_FILE_EXTENSION); exists = file.exists(); } // check if file (local or remote) exists if (exists) { int returnValue = JOptionPane.DEFAULT_OPTION; String message = "The file " + file.getName() + " already exists. Do you want to replace it?"; Object[] options = { "Cancel", "Replace" }; returnValue = JOptionPane.showOptionDialog(this.getMainFrame(), message, "Confirm replace", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (returnValue != 1) { return; } } // block GUI while saving runBlockingTask("saving session", new Runnable() { public void run() { // save getSessionManager().saveSessionAndWait(remote, file, file.getName()); menuBar.updateMenuStatus(); } }); } catch (Exception exp) { showErrorDialog("Saving session failed.", exp); return; } } menuBar.updateMenuStatus(); } catch (Exception e) { if (remote) { DialogInfo info = new DialogInfo(Severity.ERROR, "Could not connect to server.", "Currently there is a problem in the network connection or the file server. During that time remote sessions are not accessible, but data can still be saved locally.", Exceptions.getStackTrace(e), Type.MESSAGE); ChipsterDialog.showDialog(this, info, DetailsVisibility.DETAILS_HIDDEN, true); return; } else { reportException(e); } } }
Example 18
Source File: SwingClientApplication.java From chipster with MIT License | 4 votes |
@Override public void setVisualisationMethod(VisualisationMethod method, List<Variable> variables, List<DataBean> datas, FrameType target) { if (method == null) { boolean datasetsSelected = (datas != null && !datas.isEmpty()); boolean datasetsExist = !getDataManager().databeans().isEmpty(); if (datasetsSelected) { method = VisualisationMethods.DATA_DETAILS; } else if (datasetsExist) { method = VisualisationMethods.SESSION_DETAILS; } else { method = VisualisationMethods.EMPTY; } super.setVisualisationMethod(method, variables, datas, target); return; } long estimate = method.estimateDuration(datas); if (estimate > SLOW_VISUALISATION_LIMIT) { int returnValue = JOptionPane.DEFAULT_OPTION; String message = ""; int severity; // Check the running tasks if (estimate > VERY_SLOW_VISUALISATION_LIMIT) { message += "Visualising the selected large dataset with this method might stop Chipster from responding. \n" + "If you choose to continue, it's recommended to save the session before visualising."; severity = JOptionPane.WARNING_MESSAGE; } else { message += "Are you sure you want to visualise large dataset, which may " + "take several seconds?"; severity = JOptionPane.QUESTION_MESSAGE; } Object[] options = { "Cancel", "Visualise" }; returnValue = JOptionPane.showOptionDialog(this.getMainFrame(), message, "Cancel visualisation", JOptionPane.YES_NO_OPTION, severity, null, options, options[0]); if (returnValue == 1) { super.setVisualisationMethod(method, variables, datas, target); } else { return; } } else { super.setVisualisationMethod(method, variables, datas, target); } }
Example 19
Source File: AltConfigWizard.java From CogniCrypt with Eclipse Public License 2.0 | 4 votes |
/** * This method is called once the user selects an instance. It writes the instance to an xml file and calls the code generation. * * @return <code>true</code>/<code>false</code> if writing instance file and code generation are (un)successful */ @Override public boolean performFinish() { boolean ret = false; final CodeGenerators genKind = selectedTask.getCodeGen(); CodeGenerator codeGenerator = null; String additionalResources = selectedTask.getAdditionalResources(); final LocatorPage currentPage = (LocatorPage) getContainer().getCurrentPage(); IResource targetFile = (IResource) currentPage.getSelectedResource().getFirstElement(); String taskName = selectedTask.getName(); JOptionPane optionPane = new JOptionPane("CogniCrypt is now generating code that implements " + selectedTask.getDescription() + "\ninto file " + ((targetFile != null) ? targetFile.getName() : "Output.java") + ". This should take no longer than a few seconds.", JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] {}, null); JDialog waitingDialog = optionPane.createDialog("Generating Code"); waitingDialog.setModal(false); waitingDialog.setVisible(true); Configuration chosenConfig = null; try { switch (genKind) { case CrySL: CrySLBasedCodeGenerator.clearParameterCache(); File templateFile = CodeGenUtils.getResourceFromWithin(selectedTask.getCodeTemplate()).listFiles()[0]; codeGenerator = new CrySLBasedCodeGenerator(targetFile); String projectRelDir = Constants.outerFileSeparator + codeGenerator.getDeveloperProject() .getSourcePath() + Constants.outerFileSeparator + Constants.PackageName + Constants.outerFileSeparator; String pathToTemplateFile = projectRelDir + templateFile.getName(); String resFileOSPath = ""; IPath projectPath = targetFile.getProject().getRawLocation(); if (projectPath == null) { projectPath = targetFile.getProject().getLocation(); } resFileOSPath = projectPath.toOSString() + pathToTemplateFile; Files.createDirectories(Paths.get(projectPath.toOSString() + projectRelDir)); Files.copy(templateFile.toPath(), Paths.get(resFileOSPath), StandardCopyOption.REPLACE_EXISTING); codeGenerator.getDeveloperProject().refresh(); resetAnswers(); chosenConfig = new CrySLConfiguration(resFileOSPath, ((CrySLBasedCodeGenerator) codeGenerator).setUpTemplateClass(pathToTemplateFile)); break; case XSL: this.constraints = (this.constraints != null) ? this.constraints : new HashMap<>(); final InstanceGenerator instanceGenerator = new InstanceGenerator(CodeGenUtils.getResourceFromWithin(selectedTask.getModelFile()) .getAbsolutePath(), "c0_" + taskName, selectedTask.getDescription()); instanceGenerator.generateInstances(this.constraints); // Initialize Code Generation codeGenerator = new XSLBasedGenerator(targetFile, selectedTask.getCodeTemplate()); chosenConfig = new XSLConfiguration(instanceGenerator.getInstances().values().iterator() .next(), this.constraints, codeGenerator.getDeveloperProject().getProjectPath() + Constants.innerFileSeparator + Constants.pathToClaferInstanceFile); break; default: return false; } ret = codeGenerator.generateCodeTemplates(chosenConfig, additionalResources); try { codeGenerator.getDeveloperProject().refresh(); } catch (CoreException e1) { Activator.getDefault().logError(e1); } } catch (Exception ex) { Activator.getDefault().logError(ex); } finally { waitingDialog.setVisible(false); waitingDialog.dispose(); } return ret; }
Example 20
Source File: AutoUpgrade.java From netbeans with Apache License 2.0 | 4 votes |
private static void showNoteDialog (String note) { Util.setDefaultLookAndFeel(); JOptionPane p = new JOptionPane(new AutoUpgradePanel (null, note), JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION); JDialog d = Util.createJOptionDialog(p, NbBundle.getMessage (AutoUpgrade.class, "MSG_Note_Title")); d.setVisible (true); }