Java Code Examples for javax.swing.JOptionPane#showMessageDialog()

The following examples show how to use javax.swing.JOptionPane#showMessageDialog() . 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: CTableSearcherHelper.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Searches through a table.
 * 
 * @param parent Parent window used for dialogs.
 * @param table The table to search through.
 */
public static void search(final Window parent, final JTable table) {
  Preconditions.checkNotNull(parent, "IE01198: Parent argument can not be null");
  Preconditions.checkNotNull(table, "IE01199: Table argument can not be null");

  final CTableSearcher searcher = new CTableSearcher(parent, "", table, 0);

  String searchText = "";

  do {
    searchText =
        (String) JOptionPane.showInputDialog(parent, "Search", Constants.DEFAULT_WINDOW_TITLE,
            JOptionPane.QUESTION_MESSAGE, null, null, searchText);

    if ((searchText != null) && (searchText.length() > 0) && !searcher.search(searchText)) {
      JOptionPane.showMessageDialog(parent, "Search string not found",
          Constants.DEFAULT_WINDOW_TITLE, JOptionPane.ERROR_MESSAGE);
    }
  } while ((searchText != null) && (searchText.length() > 0));
}
 
Example 2
Source File: InsertRecordDialog.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void copy() {
    StringBuilder strBuffer = new StringBuilder();
    int numcols = insertRecordTableUI.getSelectedColumnCount();
    int numrows = insertRecordTableUI.getSelectedRowCount();
    int[] rowsselected = insertRecordTableUI.getSelectedRows();
    int[] colsselected = insertRecordTableUI.getSelectedColumns();
    if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0] && numrows == rowsselected.length) &&
            (numcols - 1 == colsselected[colsselected.length - 1] - colsselected[0] && numcols == colsselected.length))) {
        JOptionPane.showMessageDialog(null, "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE);
        return;
    }
    for (int i = 0; i < numrows; i++) {
        for (int j = 0; j < numcols; j++) {
            strBuffer.append(insertRecordTableUI.getValueAt(rowsselected[i], colsselected[j]));
            if (j < numcols - 1) {
                strBuffer.append("\t");
            }
        }
        strBuffer.append("\n");
    }
    StringSelection stringSelection = new StringSelection(strBuffer.toString());
    clipBoard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipBoard.setContents(stringSelection, stringSelection);
}
 
Example 3
Source File: SearchAndAnnotatePanel.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
private boolean isAnnotationEditorReady() {
  if(!annotationEditor.editingFinished() || getOwner() == null
      || annotationEditor.getAnnotationCurrentlyEdited() == null
      || annotationEditor.getAnnotationSetCurrentlyEdited() == null) {
    annotationEditorWindow.setVisible(false);
    JOptionPane.showMessageDialog(annotationEditorWindow,
        (annotationEditor.getAnnotationCurrentlyEdited() == null
            ? "Please select an existing annotation\n"
                + "or create a new one then select it."
            : "Please set all required features in the feature table."),
        "GATE", JOptionPane.INFORMATION_MESSAGE);
    annotationEditorWindow.setVisible(true);
    return false;
  } else {
    return true;
  }
}
 
Example 4
Source File: Launcher.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Shows the about dialog.
 */
protected void showAboutDialog() {
  String newline = XML.NEW_LINE;
  String vers = OSPRuntime.VERSION;
String date = OSPRuntime.getLaunchJarBuildDate();
if (date!=null) 
	vers = vers+"   "+date; //$NON-NLS-1$
String name = getClass().getSimpleName();
  String aboutString = name+" "+vers+newline                 //$NON-NLS-1$
  		+"Copyright (c) 2019 Wolfgang Christian"+newline                 //$NON-NLS-1$
      +"Open Source Physics Project"+newline                 //$NON-NLS-1$
      +"www.compadre.org/osp"+newline+newline           //$NON-NLS-1$
      +LaunchRes.getString("Label.CodeAuthor")+": Douglas Brown"; //$NON-NLS-1$ //$NON-NLS-2$
  String translator = LaunchRes.getString("Launcher.About.Translator"); //$NON-NLS-1$
  if (!translator.equals("")) { //$NON-NLS-1$
  	Locale loc = LaunchRes.resourceLocale;
  	String language = OSPRuntime.getDisplayLanguage(loc);
    aboutString += newline + newline + LaunchRes.getString("Launcher.About.Language")+ ": " //$NON-NLS-1$ //$NON-NLS-2$
    	+ language + newline;
  	aboutString += LaunchRes.getString("Launcher.About.TranslationBy") //$NON-NLS-1$
  		+": "+ translator + newline; //$NON-NLS-1$
  }
  JOptionPane.showMessageDialog(frame, aboutString, LaunchRes.getString("Help.About.Title")+" "+name, //$NON-NLS-1$//$NON-NLS-2$
    JOptionPane.INFORMATION_MESSAGE);
}
 
Example 5
Source File: Patient_Discharge_room.java    From Hospital-Management with GNU General Public License v3.0 6 votes vote down vote up
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
    try{
        int P = JOptionPane.showConfirmDialog(null," Are you sure want to delete ?","Confirmation",JOptionPane.YES_NO_OPTION);
        if (P==0)
        {
            con=Connect.ConnectDB();
            String sql= "delete from DischargePatient_Room where AdmitID = " + PatientID.getText() + "";
            pst=con.prepareStatement(sql);
            pst.execute();
            JOptionPane.showMessageDialog(this,"Successfully deleted");

            Reset();
        }
    }catch(HeadlessException | SQLException ex){
        JOptionPane.showMessageDialog(this,ex);
    }
}
 
Example 6
Source File: StockKeepingDetailsPane.java    From OpERP with MIT License 6 votes vote down vote up
public void init(StockKeeper stockKeeper) {
	this.stockKeeper = stockKeeper;
	if (stockKeeper != null) {
		stockKeeperIdField.setText(stockKeeper.getStockKeeperId()
				.toString());
		warehouseField.setText(stockKeeper.getWarehouse().toString());
		itemField.setText(stockKeeper.getItem().toString());
		quantityField.setText(stockKeeper.getQuantity().toString());
		dateField.setText(stockKeeper.getStockUpdateDate().toString());

		Stock stock = stockKeeper.getStock();
		stockWarehouseField.setText(stock.getWarehouse().toString());
		stockItemField.setText(stock.getItem().toString());
		stockQuantityField.setText(stock.getQuantity().toString());

	} else {
		dialog.dispose();
		JOptionPane.showMessageDialog(getPane(), "Null StockKeeper");
	}
}
 
Example 7
Source File: CurveHandler.java    From EccPlayground with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example 8
Source File: FileChooserDemo.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    if (customButton.isSelected()) {
        chooser.setApproveButtonText(customField.getText());
    }
    if (chooser.isMultiSelectionEnabled()) {
        chooser.setSelectedFiles(null);
    } else {
        chooser.setSelectedFile(null);
    }
    // clear the preview from the previous display of the chooser
    JComponent accessory = chooser.getAccessory();
    if (accessory != null) {
        ((FilePreviewer) accessory).loadImage(null);
    }

    if (useEmbedInWizardCheckBox.isSelected()) {
        WizardDialog wizard = new WizardDialog(frame, true);
        wizard.setVisible(true);
        wizard.dispose();
        return;
    }

    int retval = chooser.showDialog(frame, null);
    if (retval == APPROVE_OPTION) {
        JOptionPane.showMessageDialog(frame, getResultString());
    } else if (retval == CANCEL_OPTION) {
        JOptionPane.showMessageDialog(frame,
                "User cancelled operation. No file was chosen.");
    } else if (retval == ERROR_OPTION) {
        JOptionPane.showMessageDialog(frame,
                "An error occurred. No file was chosen.");
    } else {
        JOptionPane.showMessageDialog(frame, "Unknown operation occurred.");
    }
}
 
Example 9
Source File: PokemonController.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
public void delete(){
    if (panel.getTxtId().getText().trim().isEmpty()){
        JOptionPane.showMessageDialog(panel, "Sem dados para excluir.",null, JOptionPane.ERROR_MESSAGE);
        return;
    }
    int row = Integer.parseInt(panel.getTxtId().getText());
    implementPokemon.delete(row);
}
 
Example 10
Source File: FrmSimulator.java    From drmips with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("UseSpecificCatch")
public void actionPerformed(ActionEvent e) {
	try {
		loadCPU(file.getAbsolutePath());
		if(!mnuInternalWindows.isSelected())
			tabDatapath.select();
	}
	catch(Exception ex) {
		JOptionPane.showMessageDialog(FrmSimulator.this, Lang.t("invalid_file") + "\n" + ex.getMessage(), AppInfo.NAME, JOptionPane.ERROR_MESSAGE);
		LOG.log(Level.WARNING, "error loading CPU \"" + file.getName() + "\"", ex);
	}
}
 
Example 11
Source File: PreferencesPanel.java    From Spark with Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {

       if (!e.getValueIsAdjusting()) {

           if (currentPreference != null) {
               try {
                   if (currentPreference.isDataValid()) {
                       currentPreference.commit();
                   }
                   else {
                       UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                       JOptionPane.showMessageDialog(this, currentPreference.getErrorMessage(),
                               Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                       list.removeListSelectionListener(this);
                       list.setSelectedIndex(e.getLastIndex());
                       list.addListSelectionListener(this);
                   }
               }
               catch ( Throwable t )
               {
                   // This is observed with some plugins, that require classes not (no longer) provided by Spark.
                   Log.error( "An error occurred while trying to commit settings for preference: " + currentPreference.getListName(), t );
                   UIManager.put( "OptionPane.okButtonText", Res.getString( "ok" ) );
                   JOptionPane.showMessageDialog( this, "Unable to save all settings for " + currentPreference.getListName() + ":\n" + t.getMessage(),
                                                  Res.getString( "title.error" ), JOptionPane.ERROR_MESSAGE );
                   list.removeListSelectionListener( this );
                   list.setSelectedIndex( e.getLastIndex() );
                   list.addListSelectionListener( this );
               }
           }
           selectionChanged();
       }
   }
 
Example 12
Source File: DatabaseOperation.java    From Java-Simple-Hotel-Management with GNU General Public License v3.0 5 votes vote down vote up
public void deleteCustomer(int userId) throws SQLException {
    try {
        String deleteQuery = "delete from userInfo where user_id=" + userId;
        statement = conn.prepareStatement(deleteQuery);
        statement.execute();
        JOptionPane.showMessageDialog(null, "Deleted user");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.toString() + "\n" + "Delete query Failed");
    }
    finally
    {
        flushStatmentOnly();
    }

}
 
Example 13
Source File: LaserChronNUPlasmaMultiCollIonCounterFileHandler.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 *
 *
 * @param tripoliRawDataFolder
 * @return
 */
@Override
public File validateAndGetHeaderDataFromRawIntensityFile(File tripoliRawDataFolder) {
    String dialogTitle = "Select a NU Plasma IonCounter Raw Data File: *.txt";
    final String fileExtension = ".txt";
    FileFilter nonMacFileFilter = new TxtFileFilter();

    rawDataFile = null;
    rawDataFile = FileHelper.AllPlatformGetFile( //
            dialogTitle, tripoliRawDataFolder, fileExtension, nonMacFileFilter, false, new JFrame())[0];

    if (rawDataFile != null) {
        if (isValidRawDataFileType(rawDataFile)) {
            // load header data into acquisitionModel instance
            boolean success = loadDataSetupParametersFromRawDataFileHeader(rawDataFileTemplate.getAcquisitionModel());
            if (!success) {
                rawDataFile = null;
            }
        } else {
            rawDataFile = null;

            JOptionPane.showMessageDialog(
                    null,
                    new String[]{"Selected raw data file was not valid."},
                    "ET Redux Warning",
                    JOptionPane.WARNING_MESSAGE);
        }
    }

    return rawDataFile;
}
 
Example 14
Source File: GetGameSaveClientAction.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
  final Frame frame = JOptionPane.getFrameForComponent(parent);
  final File f = SaveGameFileChooser.getSaveGameLocation(frame, gameDataOnStartup);
  if (f != null) {
    final byte[] bytes = serverRemote.getSaveGame();
    try (var fileOutputStream = new FileOutputStream(f)) {
      fileOutputStream.write(bytes);
    } catch (final IOException exception) {
      log.log(Level.SEVERE, "Failed to download save game from server", exception);
    }
    JOptionPane.showMessageDialog(
        frame, "Game Saved", "Game Saved", JOptionPane.INFORMATION_MESSAGE);
  }
}
 
Example 15
Source File: frmEditCurve.java    From Course_Generator with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Duplicate the selected curve Its new name is requested
 */
private void DuplicateCurve() {
	if (!bEditMode) {
		Old_Paramfile = Paramfile;

		// -- Configuration of the panel
		JPanel panel = new JPanel(new GridLayout(0, 1));
		panel.add(new JLabel(bundle.getString("frmEditCurve.DuplicatePanel.name.text")));
		JTextField tfName = new JTextField("");
		panel.add(tfName);
		int result = JOptionPane.showConfirmDialog(this, panel,
				bundle.getString("frmEditCurve.DuplicatePanel.title"), JOptionPane.OK_CANCEL_OPTION,
				JOptionPane.PLAIN_MESSAGE);
		if ((result == JOptionPane.OK_OPTION) && (!tfName.getText().isEmpty())) {
			if (Utils.FileExist(
					Utils.getSelectedCurveFolder(CgConst.CURVE_FOLDER_USER) + tfName.getText() + ".par")) {
				JOptionPane.showMessageDialog(this, bundle.getString("frmEditCurve.DuplicatePanel.fileexist"));
				return;
			}
			param.name = tfName.getText();
			Paramfile = param.name;
			param.SaveCurve(Utils.getSelectedCurveFolder(CgConst.CURVE_FOLDER_USER) + param.name + ".par",
					settings.Unit);
			ChangeEditStatus();

			settings.SelectedCurveFolder = CgConst.CURVE_FOLDER_USER;
			UpdateSelBtStatus();
			RefreshCurveList(Utils.getSelectedCurveFolder(settings.SelectedCurveFolder));
			RefreshView();
		}
	}
}
 
Example 16
Source File: JDialogSearch.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findButtonActionPerformed
    this.Text = searchField.getText().toLowerCase();

    if (this.Text.equals("")) {
        this.Text = null;
    }
    else {
        idxSearch = searchValue(this.Text, idxSearch);
        if (idxSearch != -1) {
            idxSearch++;
            searchField.setEditable(false);
            this.findButton.setText("Next");
        }
        else {
            final JPanel errorSeachPanel = new JPanel();
            JOptionPane.showMessageDialog(errorSeachPanel, "No searched value found", "Search Result", JOptionPane.INFORMATION_MESSAGE);
            
            //to erase field, commented because if it's a wrong typing,
            // it's easier to correct with the bad entry
            //searchField.setText(null);
            
            searchField.setEditable(true);
            
            this.findButton.setText("Find");

            idxSearch = 0;
        }
    }
}
 
Example 17
Source File: BotClient.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Pops up a dialog box showing an alert
 */
public void doAlertDialog(String title, String message) {
    JTextPane textArea = new JTextPane();
    ReportDisplay.setupStylesheet(textArea);

    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                             ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    textArea.setText("<pre>" + message + "</pre>");
    JOptionPane.showMessageDialog(frame, scrollPane, title, JOptionPane.ERROR_MESSAGE);
}
 
Example 18
Source File: UserAddIFrame.java    From LibraryManagementSystem with MIT License 4 votes vote down vote up
public void actionPerformed(final ActionEvent e) {
	
	Manager ma = new Manager();
	
	if(name.getText().length() == 0){
		JOptionPane.showMessageDialog(null, "�û�������Ϊ��");
		return ;
	}
	if(name.getText().length() > 20) {
		JOptionPane.showMessageDialog(null, "�û������ó��ȴ���20");
		name.setText("");
		return ;
	}
	if(password.getText().length() == 0){
		JOptionPane.showMessageDialog(null, "���벻��Ϊ��");
		return;
	}
	if(password.getText().length() > 15){
		JOptionPane.showMessageDialog(null, "���볤�Ȳ��ô���15");
		password.setText("");
		return;
	}
	if(password.getText().length() < 6){
		JOptionPane.showMessageDialog(null, "���볤�Ȳ���С��6");
		password.setText("");
		return;
	}
	ma.setName(name.getText().trim());
	ma.setPassword(password.getText().trim());

	try {
		if(Dao.insertManagetInfo(ma)){
			JOptionPane.showMessageDialog(null, "��ӳɹ���");
			doDefaultCloseAction();
		}
		else {
			JOptionPane.showMessageDialog(null, "�û����Ѵ���");
			name.setText("");
		}
	} catch (NumberFormatException e1) {
		String message = e1.getMessage();
		int index = message.lastIndexOf(')');
		message = message.substring(index + 1);
		JOptionPane.showMessageDialog(null, message);
		e1.printStackTrace();
	} 
}
 
Example 19
Source File: MetalworksFrame.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void showAboutBox() {
    JOptionPane.showMessageDialog(this, ABOUTMSG);
}
 
Example 20
Source File: MainFrameLoadSaveHelper.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
boolean exportFilter() {
    filterOpenFileChooser.setDialogTitle(L10N.getLocalString("dlg.exportFilter_ttl", "Export filter..."));

    boolean retry = true;
    boolean alreadyExists;
    File f;
    while (retry) {
        retry = false;

        int value = filterOpenFileChooser.showSaveDialog(mainFrame);

        if (value != JFileChooser.APPROVE_OPTION) {
            return false;
        }

        f = filterOpenFileChooser.getSelectedFile();

        alreadyExists = f.exists();
        if (alreadyExists) {
            int response = JOptionPane.showConfirmDialog(filterOpenFileChooser,
                    L10N.getLocalString("dlg.file_exists_lbl", "This file already exists.\nReplace it?"),
                    L10N.getLocalString("dlg.warning_ttl", "Warning!"), JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE);

            if (response == JOptionPane.OK_OPTION) {
                retry = false;
            }
            if (response == JOptionPane.CANCEL_OPTION) {
                retry = true;
                continue;
            }

        }

        Filter suppressionFilter = mainFrame.getProject().getSuppressionFilter();
        try {
            suppressionFilter.writeEnabledMatchersAsXML(new FileOutputStream(f));
        } catch (IOException e) {
            JOptionPane.showMessageDialog(mainFrame,
                    L10N.getLocalString("dlg.saving_error_lbl", "An error occurred in saving."));
            return false;
        }
    }

    return true;
}