Example usage for javax.swing JOptionPane showConfirmDialog

List of usage examples for javax.swing JOptionPane showConfirmDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane showConfirmDialog.

Prototype

public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
        throws HeadlessException 

Source Link

Document

Brings up a dialog where the number of choices is determined by the optionType parameter.

Usage

From source file:com.biosis.biosislite.vistas.inventario.MantenimientoProveedor.java

private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed
    // TODO add your handling code here:
    List<Integer> array = new ArrayList();

    array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.LETRA, this.telefonoField, "telefono"));
    array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.LETRA, this.rucField, "ruc"));
    //        array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.direccionField, "direccion"));
    array.add(//  www  .  ja  v  a  2 s  .c  o m
            FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.nombreField, "nombreProveedor"));

    FormularioUtil.validar2(array);

    if (FormularioUtil.error) {
        JOptionPane.showMessageDialog(null, FormularioUtil.mensaje, "Mensaje del Sistema",
                JOptionPane.ERROR_MESSAGE);
        FormularioUtil.mensaje = "";
        FormularioUtil.error = false;
    } else {
        String palabra = "";
        String palabra2 = "";
        if (accion == 1) {
            palabra = "registrar";
            palabra2 = "registrado";

            if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " el Proveedor?",
                    "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                //                    proveedorControlador.getSeleccionado().setDni(idField.getText().toUpperCase());
                proveedorControlador.getSeleccionado().setNombreProveedor(nombreField.getText().toUpperCase());
                proveedorControlador.getSeleccionado().setDireccion(direccionField.getText().toUpperCase());
                proveedorControlador.getSeleccionado().setRuc(rucField.getText().toUpperCase());
                proveedorControlador.getSeleccionado().setTelefono(telefonoField.getText().toUpperCase());

                proveedorControlador.accion(accion);
                lista.add(proveedorControlador.getSeleccionado());

                if (accion == 1) {
                    JOptionPane.showMessageDialog(null, "Proveedor " + palabra2 + " correctamente",
                            "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);
                    FormularioUtil.limpiarComponente(panelDatos);
                } else {
                    JOptionPane.showMessageDialog(null, "Proveedor no " + palabra2, "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                FormularioUtil.limpiarComponente(panelDatos);
                JOptionPane.showMessageDialog(null, "Proveedor no " + palabra2, "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        } else if (accion == 2) {
            palabra = "modificar";
            palabra2 = "modificado";

            if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " el Proveedor?",
                    "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                if (accion == 2) {
                    JOptionPane.showMessageDialog(null, "Proveedor " + palabra2 + " correctamente",
                            "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);

                    lista.clear();
                    proveedorControlador.getSeleccionado()
                            .setNombreProveedor(nombreField.getText().toUpperCase());
                    proveedorControlador.getSeleccionado().setDireccion(direccionField.getText().toUpperCase());
                    proveedorControlador.getSeleccionado().setRuc(rucField.getText().toUpperCase());
                    proveedorControlador.getSeleccionado().setTelefono(telefonoField.getText().toUpperCase());

                    proveedorControlador.accion(accion);
                    listar();

                    FormularioUtil.limpiarComponente(panelDatos);

                } else {
                    JOptionPane.showMessageDialog(null, "Proveedor no " + palabra2, "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                FormularioUtil.limpiarComponente(panelDatos);
                JOptionPane.showMessageDialog(null, "Proveedor no " + palabra2, "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }

        FormularioUtil.limpiarComponente(panelDatos);
        FormularioUtil.activarComponente(panelOpciones, true);
        FormularioUtil.activarComponente(panelGuardar, false);
        FormularioUtil.activarComponente(panelDatos, false);
    }
}

From source file:com.proyecto.vista.MantenimientoAmbiente.java

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed
    // TODO add your handling code here:
    accion = Controlador.ELIMINAR;//from  www  .  jav  a 2s  . co  m
    if (tblambientes.getSelectedRow() != -1) {

        Integer codigo = tblambientes.getSelectedRow();

        Ambiente ambiente = ambienteControlador.buscarPorId(lista.get(codigo).getCodigo());

        if (ambiente != null) {
            if (JOptionPane.showConfirmDialog(null, "Desea Eliminar la Ambiente?", "Mensaje del Sistema",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                int[] filas = tblambientes.getSelectedRows();
                for (int i = 0; i < filas.length; i++) {
                    Ambiente ambiente2 = lista.get(filas[0]);
                    lista.remove(ambiente2);
                    ambienteControlador.setSeleccionado(ambiente2);
                    ambienteControlador.accion(accion);
                }
                if (ambienteControlador.accion(accion) == 3) {
                    JOptionPane.showMessageDialog(null, "Ambiente eliminada correctamente",
                            "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);

                } else {
                    JOptionPane.showMessageDialog(null, "Ambiente no eliminada", "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Ambiente no eliminado", "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } else {
        JOptionPane.showMessageDialog(null, "Debe seleccionar un Ambiente", "Mensaje del Sistema",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

public void fileSaveHex(SpinCADBank bank) {
    // Create a file chooser
    String savedPath = prefs.get("MRUHexFolder", "");

    final JFileChooser fc = new JFileChooser(savedPath);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Hex Files", "hex");
    fc.setFileFilter(filter);/*from ww  w  .j  a v a 2  s  .co m*/
    fc.showSaveDialog(new JFrame());
    File fileToBeSaved = fc.getSelectedFile();

    if (!fc.getSelectedFile().getAbsolutePath().endsWith(".hex")) {
        fileToBeSaved = new File(fc.getSelectedFile() + ".hex");
    }
    int n = JOptionPane.YES_OPTION;
    if (fileToBeSaved.exists()) {
        JFrame frame1 = new JFrame();
        n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!",
                JOptionPane.YES_NO_OPTION);
    }
    if (n == JOptionPane.YES_OPTION) {
        String filePath;
        try {
            filePath = fileToBeSaved.getPath();
            fileToBeSaved.delete();
        } finally {
        }
        for (int i = 0; i < 8; i++) {
            try {
                if (bank.patch[i].isHexFile) {
                    fileSaveHex(i, bank.patch[i].hexFile, filePath);
                } else {
                    fileSaveHex(i, bank.patch[i].patchModel.getRenderBlock().generateHex(), filePath);
                }
            } catch (IOException e) {
                JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);

                e.printStackTrace();
            }
        }
        saveMRUHexFolder(filePath);
    }
}

From source file:au.org.ala.delta.intkey.directives.invocation.UseDirectiveInvocation.java

private boolean checkCharacterUsable(au.org.ala.delta.model.Character ch, IntkeyContext context,
        boolean warnAlreadySetOrMaybeInapplicable) {
    CharacterFormatter formatter = new CharacterFormatter(true, CommentStrippingMode.RETAIN,
            AngleBracketHandlingMode.REPLACE, true, false);

    // is character fixed?
    if (context.charactersFixed()) {
        if (context.getFixedCharactersList().contains(ch.getCharacterId())) {
            if (!context.isProcessingDirectivesFile()) {
                String msg = UIUtils.getResourceString("UseDirective.CharacterFixed",
                        formatter.formatCharacterDescription(ch));
                String title = UIUtils.getResourceString("Intkey.informationDlgTitle");
                JOptionPane.showMessageDialog(UIUtils.getMainFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
            }//from w ww. j ava 2s  .c o m
            return false;
        }
    }

    // is character already used?
    if (warnAlreadySetOrMaybeInapplicable) {
        if (context.getSpecimen().hasValueFor(ch)) {
            if (context.isProcessingDirectivesFile()) {
                return true;
            } else {
                String msg = UIUtils.getResourceString("UseDirective.CharacterAlreadyUsed",
                        formatter.formatCharacterDescription(ch));
                String title = UIUtils.getResourceString("Intkey.informationDlgTitle");
                int choice = JOptionPane.showConfirmDialog(UIUtils.getMainFrame(), msg, title,
                        JOptionPane.YES_NO_OPTION);
                if (choice == JOptionPane.YES_OPTION) {
                    return true;
                } else {
                    return false;
                }
            }
        }
    }

    // is character maybe inapplicable?
    if (warnAlreadySetOrMaybeInapplicable) {
        if (context.getSpecimen().isCharacterMaybeInapplicable(ch)) {
            if (context.isProcessingDirectivesFile()) {
                return true;
            } else {
                String msg = UIUtils.getResourceString("UseDirective.CharacterMaybeInapplicable",
                        formatter.formatCharacterDescription(ch));
                String title = UIUtils.getResourceString("Intkey.informationDlgTitle");
                int choice = JOptionPane.showConfirmDialog(UIUtils.getMainFrame(), msg, title,
                        JOptionPane.YES_NO_OPTION);
                if (choice == JOptionPane.YES_OPTION) {
                    return true;
                } else {
                    return false;
                }
            }
        }
    }

    // is character unavailable?
    if (context.getSpecimen().isCharacterInapplicable(ch)) {
        if (!context.isProcessingDirectivesFile()) {
            String msg = UIUtils.getResourceString("UseDirective.CharacterUnavailable",
                    formatter.formatCharacterDescription(ch));
            String title = UIUtils.getResourceString("Intkey.informationDlgTitle",
                    formatter.formatCharacterDescription(ch));
            JOptionPane.showMessageDialog(UIUtils.getMainFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
        }
        return false;
    }

    // is character excluded?
    if (!context.getIncludedCharacters().contains(ch)) {
        if (!context.isProcessingDirectivesFile()) {
            String msg = UIUtils.getResourceString("UseDirective.CharacterExcluded",
                    formatter.formatCharacterDescription(ch));
            String title = UIUtils.getResourceString("Intkey.informationDlgTitle",
                    formatter.formatCharacterDescription(ch));
            JOptionPane.showMessageDialog(UIUtils.getMainFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
        }
        return false;
    }

    return true;
}

From source file:com.firmansyah.imam.sewa.kendaraan.FormUser.java

private void btnAktifActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAktifActionPerformed
    String status = btnAktif.getText();
    String id = inputIdUser.getText();

    System.out.println("Memilih ID : " + id);

    if (status.equals("Aktifkan")) {
        status = "1";
    } else {/*from   w w w . ja  va 2s  .  co  m*/
        status = "0";
    }

    int dialogButton = JOptionPane.YES_NO_OPTION;
    int dialogResult;
    dialogResult = JOptionPane.showConfirmDialog(this, "Anda yakin Ingin Mengubah Status User ini? ",
            "Konfirmasi", dialogButton);

    if (dialogResult == 0) {
        String url = Path.serverURL + "/user/status/" + id + "/" + status;

        getDataURL dataurl = new getDataURL();

        try {
            String data = dataurl.getData(url);
            System.out.println(data);

            if (data.equals("1")) {
                JOptionPane.showMessageDialog(this, "Status Berhasil diubah", "Informasi",
                        JOptionPane.INFORMATION_MESSAGE);

                System.out.println("Mengubah Status Data ID : " + id);
            } else {
                JOptionPane.showMessageDialog(this, "Status Tidak Berhasil diubah", "Informasi",
                        JOptionPane.ERROR_MESSAGE);
            }

        } catch (IOException ex) {
            Logger.getLogger(FormUser.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        System.out.println("Tidak Mengubah Status dari ID : " + id);
    }

    // refresh form
    refreshForm();

}

From source file:com.biosis.biosislite.vistas.inventario.MantenimientoClase.java

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed
    // TODO add your handling code here:
    accion = AbstractControlador.ELIMINAR;
    if (tblclase.getSelectedRow() != -1) {

        Integer id = tblclase.getSelectedRow();

        //            Clase clase = claseControlador.buscarPorId(lista.get(id).getId());

        if (tblclase.getSelectedRow() != -1) {
            if (JOptionPane.showConfirmDialog(null, "Desea Eliminar la Clase?", "Mensaje del Sistema",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                //                    int[] filas = tblclase.getSelectedRows();
                //                    for (int i = 0; i < filas.length; i++) {
                //                        Clase clase2 = lista.get(filas[0]);
                claseControlador.setSeleccionado(lista.get(id));
                lista.remove(lista.get(id));
                claseControlador.accion(accion);
                //                    }
                if (claseControlador.accion(accion) == 3) {
                    JOptionPane.showMessageDialog(null, "Clase eliminada correctamente", "Mensaje del Sistema",
                            JOptionPane.INFORMATION_MESSAGE);

                } else {
                    JOptionPane.showMessageDialog(null, "Clase no eliminada", "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }/*from   w  w  w.ja  va2 s.  c om*/
            } else {
                JOptionPane.showMessageDialog(null, "Clase no eliminada", "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } else {
        JOptionPane.showMessageDialog(null, "Debe seleccionar una clase", "Mensaje del Sistema",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.jvms.i18neditor.editor.Editor.java

public boolean closeCurrentProject() {
    boolean result = true;
    if (dirty) {// w  w  w .j  a v  a  2s  .  co m
        int confirm = JOptionPane.showConfirmDialog(this, MessageBundle.get("dialogs.save.text"),
                MessageBundle.get("dialogs.save.title"), JOptionPane.YES_NO_CANCEL_OPTION);
        if (confirm == JOptionPane.YES_OPTION) {
            result = saveProject();
        } else {
            result = confirm != JOptionPane.CANCEL_OPTION;
        }
    }
    if (result && project != null) {
        storeProjectState();
    }
    if (result && dirty) {
        setDirty(false);
    }
    return result;
}

From source file:com.mgmtp.perfload.loadprofiles.ui.dialog.SettingsDialog.java

private void deleteConfigFile() {
    if (JOptionPane.showConfirmDialog(null, "Delete settings?", "Confirmation",
            JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        int index = cboConfigurationFile.getSelectedIndex();
        String fileName = (String) cboConfigurationFile.getSelectedItem();
        configFiles.remove(fileName);/*from   ww  w  . j  a v a2 s  .c om*/

        index--;
        if (index < 0 && !configFiles.isEmpty()) {
            index = 0;
        }
        cboConfigurationFile.setSelectedIndex(index);

        if (configFiles.isEmpty()) {
            operations.clear();
            targets.clear();
            clients.clear();
            dirty = false;
        }
        controller.deleteSettingsFile(fileName);
    }
}

From source file:io.github.jeddict.jpa.modeler.properties.PropertiesHandler.java

public static ComboBoxPropertySupport getCollectionImplTypeProperty(
        AttributeWidget<? extends Attribute> attributeWidget, final CollectionTypeHandler colSpec) {
    JPAModelerScene modelerScene = attributeWidget.getModelerScene();
    EntityMappings em = modelerScene.getBaseElementSpec();
    ModelerFile modelerFile = modelerScene.getModelerFile();
    ComboBoxListener<String> comboBoxListener = new ComboBoxListener<String>() {
        private final Set<String> value = new HashSet<>();

        @Override/*ww  w  .  ja  va 2s .  c  om*/
        public void setItem(ComboBoxValue<String> value) {
            setCollectionImplType(value);
        }

        void setCollectionImplType(ComboBoxValue<String> value) {
            String collectionImplType = value.getValue();
            boolean valid = validateCollectionType(colSpec.getCollectionType(), collectionImplType, false);
            if (valid) {
                colSpec.setCollectionImplType(collectionImplType);
                em.getCache().addCollectionImplClass(collectionImplType);
            } else if (StringUtils.isEmpty(collectionImplType)) {
                colSpec.setCollectionImplType(null);
            }
        }

        @Override
        public ComboBoxValue<String> getItem() {
            if (!value.contains(colSpec.getCollectionImplType())) {
                value.add(colSpec.getCollectionImplType());
                em.getCache().addCollectionImplClass(colSpec.getCollectionImplType());
            }
            if (StringUtils.isNotEmpty(colSpec.getCollectionImplType())) {
                return new ComboBoxValue(colSpec.getCollectionImplType(), colSpec.getCollectionImplType()
                        .substring(colSpec.getCollectionImplType().lastIndexOf('.') + 1));
            } else {
                return new ComboBoxValue(null, EMPTY);
            }
        }

        @Override
        public List<ComboBoxValue<String>> getItemList() {
            List<ComboBoxValue<String>> comboBoxValues = new ArrayList<>();
            comboBoxValues.add(new ComboBoxValue(null, ""));
            value.addAll(em.getCache().getCollectionImplClasses());
            em.getCache().getCollectionImplClasses().stream().filter(StringUtils::isNotEmpty)
                    .forEach(collection -> {
                        Class _class;
                        try {
                            _class = Class.forName(collection);
                            comboBoxValues.add(new ComboBoxValue(_class.getName(), _class.getSimpleName()));
                        } catch (ClassNotFoundException ex) {
                            comboBoxValues.add(new ComboBoxValue(collection, collection + "(Not Exist)"));
                        }
                    });
            return comboBoxValues;
        }

        @Override
        public String getDefaultText() {
            return EMPTY;
        }

        @Override
        public ActionHandler getActionHandler() {
            return ActionHandler.getInstance(() -> {
                String collectionType = NBModelerUtil.browseClass(modelerFile);
                try {
                    if (Collection.class.isAssignableFrom(Class.forName(collectionType))
                            || Map.class.isAssignableFrom(Class.forName(collectionType))) {
                        return new ComboBoxValue<>(collectionType,
                                collectionType.substring(collectionType.lastIndexOf('.') + 1));
                    }
                } catch (ClassNotFoundException ex) {

                }
                throw new IllegalStateException("Invalid Collection/Map type");
            }).afterCreation(e -> em.getCache().addCollectionImplClass(e.getValue()))
                    .afterDeletion(e -> em.getCache().getCollectionImplClasses().remove(e.getValue()))
                    .beforeDeletion(
                            () -> JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
                                    "Are you sue you want to delete this collection implementation class ?",
                                    "Delete Collection Implementation Class", JOptionPane.OK_CANCEL_OPTION));
        }
    };
    org.netbeans.modeler.config.element.Attribute attribute = new org.netbeans.modeler.config.element.Attribute(
            "collectionImplType", "Collection Implementation Type", "");
    attribute.setAfter("collectionType");
    return new ComboBoxPropertySupport(modelerScene.getModelerFile(), attribute, comboBoxListener);
}

From source file:de.ailis.xadrian.frames.MainFrame.java

/**
 * Closes the current tab. Prompts for saving unsaved changes before
 * closing. Returns true if the tab was closed or false if it was not
 * closed./*from   w  ww .  j av a 2  s  . c  om*/
 *
 * @return True if tab was closed, false if not
 */
public boolean closeCurrentTab() {
    final Component current = getCurrentTab();
    if (current != null) {
        final ComplexEditor editor = (ComplexEditor) current;
        if (editor.isChanged()) {
            final int answer = JOptionPane.showConfirmDialog(null,
                    I18N.getString("confirm.saveChanges", editor.getComplex().getName()),
                    I18N.getTitle("confirm.saveChanges"), JOptionPane.YES_NO_CANCEL_OPTION);
            if (answer == JOptionPane.CLOSED_OPTION)
                return false;
            if (answer == JOptionPane.CANCEL_OPTION)
                return false;
            if (answer == JOptionPane.YES_OPTION) {
                editor.save();
                if (editor.isChanged())
                    return false;
            }
        }

        this.tabs.remove(current);

        // Replace the tab control with the welcome panel if no tabs present
        if (this.tabs.getTabCount() == 0) {
            remove(this.tabs);
            add(this.welcomePanel, BorderLayout.CENTER);
            repaint();
        }

        fireChange();
        return true;
    }
    return false;
}