本文整理了Java中javax.swing.JOptionPane.showConfirmDialog()
方法的一些代码示例,展示了JOptionPane.showConfirmDialog()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JOptionPane.showConfirmDialog()
方法的具体详情如下:
包路径:javax.swing.JOptionPane
类名称:JOptionPane
方法名:showConfirmDialog
暂无
代码示例来源:origin: libgdx/packr
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());
}
}
代码示例来源:origin: stackoverflow.com
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());
}
}
}
代码示例来源:origin: marytts/marytts
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);
}
代码示例来源:origin: libgdx/libgdx
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);
代码示例来源:origin: libgdx/libgdx
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);
代码示例来源:origin: stackoverflow.com
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());
}
}
}
代码示例来源:origin: kiegroup/optaplanner
@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();
}
}
代码示例来源:origin: skylot/jadx
private void initUI() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JOptionPane.showMessageDialog(
this,
NLS.str("msg.language_changed", settings.getLangLocale()),
int res = JOptionPane.showConfirmDialog(
JadxSettingsWindow.this,
NLS.str("preferences.reset_message"),
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
contentPane.add(panel, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.PAGE_END);
getRootPane().setDefaultButton(saveBtn);
代码示例来源:origin: kiegroup/optaplanner
@Override
public void actionPerformed(ActionEvent e) {
JPanel listFieldsPanel = new JPanel(new GridLayout(2, 1));
List<Bed> bedList = getSolution().getBedList();
// Add 1 to array size to add null, which makes the entity unassigned
JComboBox bedListField = new JComboBox(
bedList.toArray(new Object[bedList.size() + 1]));
LabeledComboBoxRenderer.applyToComboBox(bedListField);
bedListField.setSelectedItem(bedDesignation.getBed());
listFieldsPanel.add(bedListField);
int result = JOptionPane.showConfirmDialog(PatientAdmissionSchedulePanel.this.getRootPane(),
listFieldsPanel, "Select bed for " + bedDesignation.getAdmissionPart().getPatient().getName(),
JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
Bed toBed = (Bed) bedListField.getSelectedItem();
solutionBusiness.doChangeMove(bedDesignation, "bed", toBed);
solverAndPersistenceFrame.resetScreen();
}
}
代码示例来源:origin: stackoverflow.com
PlayerEditorPanel playerEditorPane = new PlayerEditorPanel();
int result = JOptionPane.showConfirmDialog(null, playerEditorPane,
"Edit Player", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE);
FieldTitle fieldTitle = FieldTitle.values()[i];
gbc = createGbc(0, i);
add(new JLabel(fieldTitle.getTitle() + ":", JLabel.LEFT), gbc);
gbc = createGbc(1, i);
JTextField textField = new JTextField(10);
add(textField, gbc);
代码示例来源:origin: stackoverflow.com
btn2= new JButton("Cancel");
setLayout(new FlowLayout());
add(btn);
add(btn2);
btn.addActionListener(this);
btn2.addActionListener(this);
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btn){
JOptionPane.showMessageDialog(null, "Hi");
JOptionPane.showConfirmDialog(null, "Hi there");
代码示例来源:origin: stackoverflow.com
JPanel panel = new JPanel( new BorderLayout() );
JPanel north = new JPanel();
north.add( new JTextField(10) );
north.add( new JTextField(10) );
north.add( new JTextField(10) );
north.add( new JTextField(10) );
north.add( new JTextField(10) );
panel.add(new JScrollPane(textArea));
int result = JOptionPane.showConfirmDialog(
this, panel, "addRecord", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
代码示例来源:origin: MER-C/wiki-java
/**
* Creates and shows user a login screen, returning user login details in a String array. Does not check to see if login details are
* valid.
*
* @param title The title of the login window
* @return An array of length 2, in the form {username, password}.
*/
public static String[] showLoginScreen(String title)
{
JTextField u = new JTextField(20);
JPasswordField px = new JPasswordField(20);
if (JOptionPane.showConfirmDialog(null, GUIUtils.buildForm(title, new JLabel("Username:", JLabel.TRAILING), u, new JLabel("Password:",
JLabel.TRAILING), px), title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) != JOptionPane.OK_OPTION)
System.exit(0);
return new String[] { u.getText().trim(), new String(px.getPassword()) };
}
}
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: marytts/marytts
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;
代码示例来源:origin: chewiebug/GCViewer
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);
}
}
}
代码示例来源:origin: stackoverflow.com
contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
JPanel panInputLabels = new JPanel(new BorderLayout(0, 5));
JPanel panInputFields = new JPanel(new BorderLayout(0, 5));
JPanel panProgressLabels = new JPanel(new BorderLayout(0, 5));
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());
JOptionPane.showMessageDialog(this, "The source file/directory does not exist!", "ERROR", JOptionPane.ERROR_MESSAGE);
return;
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;
File srcFile = new File(sourceFile, filePath);
File destFile = new File(targetFile, filePath);
代码示例来源:origin: alibaba/jstorm
String[] prompt,
boolean[] echo) {
panel = new JPanel();
panel.setLayout(new GridBagLayout());
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,
代码示例来源:origin: kiegroup/optaplanner
@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();
}
}
代码示例来源:origin: marytts/marytts
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);
}
内容来源于网络,如有侵权,请联系作者删除!