public static void main (String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("My Test App"); frame.setSize(480, 320); frame.setVisible(true); JOptionPane.showConfirmDialog(null, "Working dir: " + new File(".").getAbsolutePath()); } }
import javax.swing.*; public class JOptionPaneMultiInput { public static void main(String[] args) { JTextField xField = new JTextField(5); JTextField yField = new JTextField(5); JPanel myPanel = new JPanel(); myPanel.add(new JLabel("x:")); myPanel.add(xField); myPanel.add(Box.createHorizontalStrut(15)); // a spacer myPanel.add(new JLabel("y:")); myPanel.add(yField); int result = JOptionPane.showConfirmDialog(null, myPanel, "Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { System.out.println("x value: " + xField.getText()); System.out.println("y value: " + yField.getText()); } } }
public void uninstallSelectedLanguagesAndVoices() { List<ComponentDescription> toUninstall = getComponentsSelectedForUninstall(); if (toUninstall.size() == 0) { JOptionPane.showMessageDialog(this, "You have not selected any uninstallable components"); return; } int returnValue = JOptionPane.showConfirmDialog(this, "Uninstall " + toUninstall.size() + " components?\n", "Proceed with uninstall?", JOptionPane.YES_NO_OPTION); if (returnValue != JOptionPane.YES_OPTION) { System.err.println("Aborting uninstall."); return; } System.out.println("Starting uninstall"); showProgressPanel(toUninstall, false); }
JOptionPane.showConfirmDialog(this, "Input directory not specified!", "Info missing", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE); return; JOptionPane.showConfirmDialog(this, "Output directory not specified!", "Info missing", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE); return; int targetSampleRate = Integer.parseInt((String) comboSampleRate.getSelectedItem()); String soxPath = tfSoxPath.getText(); if (downSample && !new File(soxPath).exists()) { JOptionPane.showConfirmDialog(this, "Please indicate location of 'sox' tool\n" + "or deactivate sample rate conversion.", "Info missing", JOptionPane.OK_OPTION); return; JOptionPane.showConfirmDialog(this, "Nothing to do!", "Info missing", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE); return;
public static boolean isSdkUpToDate (String sdkLocation) { File buildTools = new File(sdkLocation, "build-tools"); if (!buildTools.exists()) { JOptionPane.showMessageDialog(null, "You have no build tools!\nUpdate your Android SDK with build tools version: " + DependencyBank.buildToolsVersion); return false; File apis = new File(sdkLocation, "platforms"); if (!apis.exists()) { JOptionPane.showMessageDialog(null, "You have no Android APIs!\nUpdate your Android SDK with API level: " + DependencyBank.androidAPILevel); return false; int[] targetToolVersion = convertTools(DependencyBank.buildToolsVersion); if (compareVersions(targetToolVersion, localToolVersion)) { int value = JOptionPane.showConfirmDialog(null, "You have a more recent version of android build tools than the recommended.\nDo you want to use your more recent version?", "Warning!", JOptionPane.YES_NO_OPTION); if (value != 0) { JOptionPane.showMessageDialog(null, "Using build tools: " + DependencyBank.buildToolsVersion); } else { DependencyBank.buildToolsVersion = newestLocalTool; int value = JOptionPane.showConfirmDialog(null, "You have a more recent Android API than the recommended.\nDo you want to use your more recent version?", "Warning!", JOptionPane.YES_NO_OPTION);
void generate () { final String name = ui.form.nameText.getText().trim(); if (name.length() == 0) { JOptionPane.showMessageDialog(this, "Please enter a project name."); return; JOptionPane.showMessageDialog(this, "Please enter a package name."); return; JOptionPane.showMessageDialog(this, "Invalid package name"); return; File sdkLocationFile = new File(sdkLocation); try { //give them a poke in the right direction if (System.getProperty("os.name").contains("Windows")) { Runtime.getRuntime().exec("\"" + replaced + "\\SDK Manager.exe\""); } else { File sdkManager = new File(sdkLocation, "tools/android"); Runtime.getRuntime().exec(new String[] {sdkManager.getAbsolutePath(), "sdk"}); int value = JOptionPane.showConfirmDialog(this, "The destination is not empty, do you want to overwrite?", "Warning!", JOptionPane.YES_NO_OPTION); if (value != 0) { return; JLabel infoLabel = new JLabel("<html><br><br>The project can be generated, but you wont be able to use these extensions in the respective sub modules<br>Please see the link to learn about extensions</html>"); infoLabel.setAlignmentX(Component.CENTER_ALIGNMENT); panel.add(infoLabel);
@Override public void approveSelection() { File selectedFile = getSelectedFile(); if (selectedFile.exists() && getDialogType() == JFileChooser.SAVE_DIALOG) { int result = JOptionPane.showConfirmDialog(this, "Do you want to overwrite?", "File already exists", JOptionPane.YES_NO_OPTION); if (result != JOptionPane.YES_OPTION) { cancelSelection(); return; } } super.approveSelection(); } };
public synchronized void storeCurve() { if (curve != null && initialized) { File f = new File(fileName); int dialogResult = JOptionPane.showConfirmDialog(null, "Would You Like to Save your Curve? (File " + fileName + ")", "Curve saving", JOptionPane.YES_NO_OPTION); if (dialogResult == JOptionPane.YES_OPTION) { try { XMLPersistanceHelper.saveObjectToFile(f, curve); } catch (Exception e) { LOG.warn(e.getLocalizedMessage(), e); JOptionPane.showMessageDialog(null, e, "Error saving", JOptionPane.ERROR_MESSAGE); } } } }
import java.io.File; import javax.swing.*; public class QuickTest { public static void main(String[] args) throws Exception { File[] files = new File(System.getProperty("user.home")).listFiles(); JFrame f = new JFrame("Faux J-Link"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JEditorPane jep = new JEditorPane(); f.add(new JScrollPane(jep)); f.setSize(600,400); f.setLocationByPlatform(true); f.setVisible(true); JComboBox choices = new JComboBox(files); int result = JOptionPane.showConfirmDialog(f, choices); if (result==JOptionPane.OK_OPTION) { System.out.println("OK"); File file = files[choices.getSelectedIndex()]; jep.setPage(file.toURI().toURL()); } } }
@Override public void actionPerformed(ActionEvent e) { JPanel listFieldsPanel = new JPanel(new GridLayout(1, 2)); listFieldsPanel.add(new JLabel("Computer:")); List<CloudComputer> computerList = getSolution().getComputerList(); // Add 1 to array size to add null, which makes the entity unassigned JComboBox computerListField = new JComboBox( computerList.toArray(new Object[computerList.size() + 1])); LabeledComboBoxRenderer.applyToComboBox(computerListField); computerListField.setSelectedItem(process.getComputer()); listFieldsPanel.add(computerListField); int result = JOptionPane.showConfirmDialog(CloudBalancingPanel.this.getRootPane(), listFieldsPanel, "Select computer", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { CloudComputer toComputer = (CloudComputer) computerListField.getSelectedItem(); if (process.getComputer() != toComputer) { solutionBusiness.doChangeMove(process, "computer", toComputer); } solverAndPersistenceFrame.resetScreen(); } }
JOptionPane.showMessageDialog( this, NLS.str("msg.language_changed", settings.getLangLocale()), int res = JOptionPane.showConfirmDialog( JadxSettingsWindow.this, NLS.str("preferences.reset_message"), contentPane.add(panel, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.PAGE_END); getRootPane().setDefaultButton(saveBtn);
add(new JScrollPane(textArea)); add(new JButton(new AbstractAction("Get Player Information") { int result = JOptionPane.showConfirmDialog(null, playerEditorPanel, "Edit Player", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true);
JOptionPane.showConfirmDialog(this, "Input directory not specified!", "Info missing", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE); return; JOptionPane.showConfirmDialog(this, "Output directory not specified!", "Info missing", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE); return; int targetSampleRate = Integer.parseInt((String) comboSampleRate.getSelectedItem()); String soxPath = tfSoxPath.getText(); if (downSample && !new File(soxPath).exists()) { JOptionPane.showConfirmDialog(this, "Please indicate location of 'sox' tool\n" + "or deactivate sample rate conversion.", "Info missing", JOptionPane.OK_OPTION); return; JOptionPane.showConfirmDialog(this, "Nothing to do!", "Info missing", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE); return;
public void exportFile(final GCModel model, File file, final String extension, final DataWriterType dataWriterType) { if (file.toString().indexOf('.') == -1) { file = new File(file.toString() + extension); } if (!file.exists() || JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(gcViewer, LocalisationHelper.getString("fileexport_dialog_confirm_overwrite"), LocalisationHelper.getString("fileexport_dialog_title"), JOptionPane.YES_NO_OPTION)) { try (DataWriter writer = DataWriterFactory.getDataWriter(file, dataWriterType)) { writer.write(model); } catch (Exception ioe) { //ioe.printStackTrace(); JOptionPane.showMessageDialog(gcViewer, ioe.getLocalizedMessage(), LocalisationHelper.getString("fileexport_dialog_write_file_failed"), JOptionPane.ERROR_MESSAGE); } } }
JPanel panProgressBars = new JPanel(new BorderLayout(0, 5)); panInputLabels.add(lblSource, BorderLayout.NORTH); panInputLabels.add(lblTarget, BorderLayout.CENTER); panInputFields.add(txtSource, BorderLayout.NORTH); panInputFields.add(txtTarget, BorderLayout.CENTER); panProgressLabels.add(lblProgressAll, BorderLayout.NORTH); File source = new File(txtSource.getText()); File target = new File(txtTarget.getText()); if(!source.exists()) JOptionPane.showMessageDialog(this, "The source file/directory does not exist!", "ERROR", JOptionPane.ERROR_MESSAGE); return; if(!target.exists() && source.isDirectory()) target.mkdirs(); else int option = JOptionPane.showConfirmDialog(this, "The target file/directory already exists, do you want to overwrite it?", "Overwrite the target", JOptionPane.YES_NO_OPTION); if(option != JOptionPane.YES_OPTION) return; if(!targetFile.exists()) targetFile.mkdirs(); File srcFile = new File(sourceFile, filePath); File destFile = new File(targetFile, filePath);
@Override public void approveSelection() { File file = this.getSelectedFile(); if (file.exists() && this.getDialogType() == JFileChooser.SAVE_DIALOG) { int replace = JOptionPane.showConfirmDialog( this, file.getName() +" "+ I18n.valueByKey("LIST_EXPORT_CONFIRM_LABEL"), I18n.valueByKey("LIST_EXPORT_CONFIRM_TITLE"), JOptionPane.YES_NO_OPTION ); switch (replace) { case JOptionPane.YES_OPTION: super.approveSelection(); return; case JOptionPane.NO_OPTION: case JOptionPane.CLOSED_OPTION: return; case JOptionPane.CANCEL_OPTION: this.cancelSelection(); return; default: break; } } else { super.approveSelection(); } } };
private void exportPressed() { pemEncode = jcbExportPem.isSelected(); String exportFileStr = jtfExportFile.getText().trim(); if (exportFileStr.length() == 0) { JOptionPane.showMessageDialog(this, res.getString("DExportPublicKeyOpenSsl.ExportFileRequired.message"), res.getString("DExportPublicKeyOpenSsl.Simple.Title"), JOptionPane.WARNING_MESSAGE); return; } File exportFile = new File(exportFileStr); if (exportFile.isFile()) { String message = MessageFormat.format(res.getString("DExportPublicKeyOpenSsl.OverWriteExportFile.message"), exportFile); int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportPublicKeyOpenSsl.Simple.Title"), JOptionPane.YES_NO_OPTION); if (selected != JOptionPane.YES_OPTION) { return; } } this.exportFile = exportFile; exportSelected = true; closeDialog(); }
public void actionPerformed(ActionEvent actionEvent) { if (hideChatHistory.isSelected()) { UIManager.put("OptionPane.yesButtonText", Res.getString("yes")); UIManager.put("OptionPane.noButtonText", Res.getString("no")); UIManager.put("OptionPane.cancelButtonText", Res.getString("cancel")); int ok = JOptionPane.showConfirmDialog(this, Res.getString("message.delete.all.history"), Res.getString("title.confirmation"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (ok == JOptionPane.YES_OPTION) { File transcriptDir = new File(SparkManager.getUserDirectory(), "transcripts"); File[] files = transcriptDir.listFiles(); hidePrevChatHistory.setEnabled(false); hidePrevChatHistory.setSelected(false); for (File transcriptFile : files) { transcriptFile.delete(); } } } else { hidePrevChatHistory.setEnabled(true); } }
gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridx = 0; panel.add(new JLabel(instruction), gbc); gbc.gridy++; gbc.gridx = 0; gbc.weightx = 1; panel.add(new JLabel(prompt[i]), gbc); texts[i] = new JPasswordField(20); panel.add(texts[i], gbc); gbc.gridy++; if (JOptionPane.showConfirmDialog(null, panel, destination + ": " + name, JOptionPane.OK_CANCEL_OPTION,
@Override public void actionPerformed(ActionEvent e) { JPanel messagePanel = new JPanel(new BorderLayout()); messagePanel.add(new JLabel("Move to row: "), BorderLayout.WEST); List<Row> rowList = getSolution().getRowList(); // Add 1 to array size to add null, which makes the entity unassigned JComboBox rowListField = new JComboBox( rowList.toArray(new Object[rowList.size() + 1])); LabeledComboBoxRenderer.applyToComboBox(rowListField); rowListField.setSelectedItem(queen.getRow()); messagePanel.add(rowListField, BorderLayout.CENTER); int result = JOptionPane.showConfirmDialog(NQueensPanel.this.getRootPane(), messagePanel, "Queen in column " + queen.getColumn().getIndex(), JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { Row toRow = (Row) rowListField.getSelectedItem(); solutionBusiness.doChangeMove(queen, "row", toRow); solverAndPersistenceFrame.resetScreen(); } }