Example usage for javax.swing JOptionPane WARNING_MESSAGE

List of usage examples for javax.swing JOptionPane WARNING_MESSAGE

Introduction

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

Prototype

int WARNING_MESSAGE

To view the source code for javax.swing JOptionPane WARNING_MESSAGE.

Click Source Link

Document

Used for warning messages.

Usage

From source file:misc.TextBatchPrintingDemo.java

/**
 * Print all selected pages in separate threads, one thread per page.
 *///from w w  w  .j av  a  2 s .  c o m
void printSelectedPages() {
    DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
    int n = pages.getSize();
    if (n < 1) {
        messageArea.setText("No pages selected");
        return;
    }
    if (printService == null) {
        messageArea.setText("No print service");
        return;
    }

    for (int i = 0; i < n; i++) {
        final PageItem item = (PageItem) pages.getElementAt(i);
        // This method is called from EDT.  Printing is a time-consuming
        // task, so it should be done outside EDT, in a separate thread.
        Runnable printTask = new Runnable() {
            public void run() {
                try {
                    item.print(
                            // Two "false" args mean "no print dialog" and
                            // "non-interactive" (ie, batch-mode printing).
                            null, null, false, printService, null, false);
                } catch (PrinterException pe) {
                    JOptionPane.showMessageDialog(null, "Error printing " + item.getPage() + "\n" + pe,
                            "Print Error", JOptionPane.WARNING_MESSAGE);
                }
            }
        };
        new Thread(printTask).start();
    }

    pages.removeAllElements();
    messageArea.setText(n + (n > 1 ? " pages" : " page") + " printed");
}

From source file:client.ui.Container.java

private void buttonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonMouseReleased
    String campaignId = campaignInput.getText().trim();
    String workerId = workerInput.getText().trim();

    if (campaignId.length() < 1) {
        JOptionPane.showMessageDialog(this, "Please introduce the Campaign ID", "Error",
                JOptionPane.WARNING_MESSAGE);
        return;/* ww  w.  ja  v  a2  s  .  co m*/

    } else if (workerId.length() < 1) {
        JOptionPane.showMessageDialog(this, "Please introduce the Worker ID", "Error",
                JOptionPane.WARNING_MESSAGE);
        return;
    }

    campaignInput.setEnabled(false);
    workerInput.setEnabled(false);
    urlInput.setEnabled(false);
    button.setEnabled(false);

    progress.setValue(0);
    progress.setIndeterminate(true);

    try {
        String url = urlInput.getText();
        if (url.endsWith("/") == false) {
            url += "/";
        }
        test(url + campaignId + "/" + workerId);

        /**/
    } catch (Exception e) {
        campaignInput.setEnabled(true);
        workerInput.setEnabled(true);
        urlInput.setEnabled(true);

        progress.setIndeterminate(false);
        progress.setValue(0);

        JOptionPane.showMessageDialog(this, "Invalid url: " + e.getMessage(), "Error",
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:com.iucosoft.eavertizare.gui.models.ClientiTableModel.java

public void findClient(Frame frame, String nume, String prenume) {
    clearModel();/*w ww.ja  va 2 s  .  c  om*/
    Client client;
    List<Client> listaClienti = null;
    List<Firma> listaFirme = firmaDao.findAll();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
    int nr = 1;
    Vector rowData = null;
    for (Firma firma : listaFirme) {
        client = clientsDao.findClient(firma, nume, prenume);
        if (client != null) {
            rowData = new Vector();
            rowData.addElement(nr++);
            rowData.addElement(client.getNume());
            rowData.addElement(client.getPrenume());
            rowData.addElement(client.getNrTelefon());
            rowData.addElement(client.getEmail());
            rowData.addElement(sdf.format(client.getDateExpirare()));
            rowData.addElement(client.getFirma().getNumeFirma());
            rowData.addElement(client.isTrimis());
            super.addRow(rowData);
        }
    }
    if (rowData == null) {
        refreshModel();
        JOptionPane.showMessageDialog(frame,
                "Nu exista client cu asa nume = " + nume + " si prenume = " + prenume, "Error",
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:com.diversityarrays.kdxplore.trials.SampleGroupExportDialog.java

static public Set<Integer> getExcludedTraitIds(Component comp, String msgTitle, KdxploreDatabase kdxdb,
        SampleGroup sg) {//from ww  w . j a va 2  s .  c o m
    Set<Integer> excludeTheseTraitIds = new HashSet<>();

    try {
        Set<Integer> traitIds = collectTraitIdsFromSamples(kdxdb, sg);
        List<Trait> undecidableTraits = new ArrayList<>();
        Set<Integer> missingTraitIds = new TreeSet<>();
        Map<Integer, Trait> traitMap = kdxdb.getKDXploreKSmartDatabase().getTraitMap();
        for (Integer traitId : traitIds) {
            Trait t = traitMap.get(traitId);
            if (t == null) {
                missingTraitIds.add(traitId);
            } else if (TraitLevel.UNDECIDABLE == t.getTraitLevel()) {
                undecidableTraits.add(t);
            }
        }

        if (!missingTraitIds.isEmpty()) {
            String msg = missingTraitIds.stream().map(i -> Integer.toString(i))
                    .collect(Collectors.joining(","));
            MsgBox.error(comp, msg, "Missing Trait IDs");
            return null;
        }

        if (!undecidableTraits.isEmpty()) {
            String msg = undecidableTraits.stream().map(Trait::getTraitName)
                    .collect(Collectors.joining("\n", "Traits that are neither Plot nor Sub-Plot:\n",
                            "\nDo you want to continue and Exclude samples for those Traits?"));

            if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(comp, msg, msgTitle,
                    JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE)) {
                return null;
            }

            Set<Integer> tmp = undecidableTraits.stream().map(Trait::getTraitId).collect(Collectors.toSet());

            excludeTheseTraitIds.addAll(tmp);
        }
    } catch (IOException e) {
        MsgBox.error(comp, "Unable to read samples from database\n" + e.getMessage(), msgTitle);
        return null;
    }

    return excludeTheseTraitIds;
}

From source file:com.sec.ose.osi.ui.frm.main.report.JPanReportMain.java

private boolean checkIdentifyCompletion(String projectName) {

    if (IdentifyQueue.getInstance().isIdentifyCompleted(projectName) == true) {
        return true;
    }//  w w  w  .j  av a2  s  .  c  o  m

    String[] buttonList = { "Yes", "No" };
    int choice = JOptionPane.showOptionDialog(null,
            "Identify transactions for " + projectName + " are on updating.\n"
                    + "You must wait for completing all transactions to obtain accurate report.\n"
                    + "Are you sure to generate the report anyway?\n",
            "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, buttonList, "Yes");

    if (choice == JOptionPane.YES_OPTION) {
        return true;
    }

    return false;
}

From source file:canreg.client.gui.management.CanReg4MigrationInternalFrame.java

@Action
public void cancelAction() throws RemoteException, IOException {
    isPaused = true;/*from ww w .  j  a  v a2  s. c  o  m*/
    if (cTask != null) {
        if (JOptionPane.showInternalConfirmDialog(
                CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                        .getString("REALLY_CANCEL?"),
                java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                        .getString("PLEASE_CONFIRM."),
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            cTask.cancel(true);
            JOptionPane.showInternalMessageDialog(
                    CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                    java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                            .getString("IMPORT_OF_FILE_INTERUPTED"),
                    java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                            .getString("WARNING"),
                    JOptionPane.WARNING_MESSAGE);
            cTask = null;
            this.dispose();
        } else {
            isPaused = false;
        }
    } else {
        this.dispose();
    }
}

From source file:com.edduarte.protbox.ui.windows.RestoreFileWindow.java

private RestoreFileWindow(final PReg registry) {
    super();//from   w w  w .  j  av a  2  s .c  o m
    setLayout(null);

    final JTextField searchField = new JTextField();
    searchField.setLayout(null);
    searchField.setBounds(2, 2, 301, 26);
    searchField.setBorder(new LineBorder(Color.lightGray));
    searchField.setFont(Constants.FONT);
    add(searchField);

    final JLabel noBackupFilesLabel = new JLabel("<html>No backups files were found!<br><br>"
            + "<font color=\"gray\">If you think there is a problem with the<br>"
            + "backup system, please create an issue here:<br>"
            + "<a href=\"#\">https://github.com/com.edduarte/protbox/issues</a></font></html>");
    noBackupFilesLabel.setLayout(null);
    noBackupFilesLabel.setBounds(20, 50, 300, 300);
    noBackupFilesLabel.setFont(Constants.FONT.deriveFont(14f));
    noBackupFilesLabel.addMouseListener((OnMouseClick) e -> {
        String urlPath = "https://github.com/com.edduarte/protbox/issues";

        try {

            if (Desktop.isDesktopSupported()) {
                Desktop.getDesktop().browse(new URI(urlPath));

            } else {
                if (SystemUtils.IS_OS_WINDOWS) {
                    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + urlPath);

                } else {
                    java.util.List<String> browsers = Lists.newArrayList("firefox", "opera", "safari",
                            "mozilla", "chrome");

                    for (String browser : browsers) {
                        if (Runtime.getRuntime().exec(new String[] { "which", browser }).waitFor() == 0) {

                            Runtime.getRuntime().exec(new String[] { browser, urlPath });
                            break;
                        }
                    }
                }
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    });

    DefaultMutableTreeNode rootTreeNode = registry.buildEntryTree();
    final JTree tree = new JTree(rootTreeNode);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    if (rootTreeNode.getChildCount() == 0) {
        searchField.setEnabled(false);
        add(noBackupFilesLabel);
    }
    expandTree(tree);
    tree.setLayout(null);
    tree.setRootVisible(false);
    tree.setEditable(false);
    tree.setCellRenderer(new SearchableTreeCellRenderer(searchField));
    searchField.addKeyListener((OnKeyReleased) e -> {

        // update and expand tree
        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        model.nodeStructureChanged((TreeNode) model.getRoot());
        expandTree(tree);
    });
    final JScrollPane scroll = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setBorder(new DropShadowBorder());
    scroll.setBorder(new LineBorder(Color.lightGray));
    scroll.setBounds(2, 30, 334, 360);
    add(scroll);

    JLabel close = new JLabel(new ImageIcon(Constants.getAsset("close.png")));
    close.setLayout(null);
    close.setBounds(312, 7, 18, 18);
    close.setFont(Constants.FONT);
    close.setForeground(Color.gray);
    close.addMouseListener((OnMouseClick) e -> dispose());
    add(close);

    final JLabel permanentDeleteButton = new JLabel(new ImageIcon(Constants.getAsset("permanent.png")));
    permanentDeleteButton.setLayout(null);
    permanentDeleteButton.setBounds(91, 390, 40, 39);
    permanentDeleteButton.setBackground(Color.black);
    permanentDeleteButton.setEnabled(false);
    permanentDeleteButton.addMouseListener((OnMouseClick) e -> {
        if (permanentDeleteButton.isEnabled()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            PbxEntry entry = (PbxEntry) node.getUserObject();

            if (JOptionPane.showConfirmDialog(null,
                    "Are you sure you wish to permanently delete '" + entry.realName()
                            + "'?\nThis file and its "
                            + "backup copies will be deleted immediately. You cannot undo this action.",
                    "Confirm Cancel", JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {

                registry.permanentDelete(entry);
                dispose();
                RestoreFileWindow.getInstance(registry);

            } else {
                setVisible(true);
            }
        }
    });
    add(permanentDeleteButton);

    final JLabel configBackupsButton = new JLabel(new ImageIcon(Constants.getAsset("config.png")));
    configBackupsButton.setLayout(null);
    configBackupsButton.setBounds(134, 390, 40, 39);
    configBackupsButton.setBackground(Color.black);
    configBackupsButton.setEnabled(false);
    configBackupsButton.addMouseListener((OnMouseClick) e -> {
        if (configBackupsButton.isEnabled()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            PbxEntry entry = (PbxEntry) node.getUserObject();
            if (entry instanceof PbxFile) {
                PbxFile pbxFile = (PbxFile) entry;

                JFrame frame = new JFrame("Choose backup policy");
                Object option = JOptionPane.showInputDialog(frame,
                        "Choose below the backup policy for this file:", "Choose backup",
                        JOptionPane.QUESTION_MESSAGE, null, PbxFile.BackupPolicy.values(),
                        pbxFile.getBackupPolicy());

                if (option == null) {
                    setVisible(true);
                    return;
                }
                PbxFile.BackupPolicy pickedPolicy = PbxFile.BackupPolicy.valueOf(option.toString());
                pbxFile.setBackupPolicy(pickedPolicy);
            }
            setVisible(true);
        }
    });
    add(configBackupsButton);

    final JLabel restoreBackupButton = new JLabel(new ImageIcon(Constants.getAsset("restore.png")));
    restoreBackupButton.setLayout(null);
    restoreBackupButton.setBounds(3, 390, 85, 39);
    restoreBackupButton.setBackground(Color.black);
    restoreBackupButton.setEnabled(false);
    restoreBackupButton.addMouseListener((OnMouseClick) e -> {
        if (restoreBackupButton.isEnabled()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            PbxEntry entry = (PbxEntry) node.getUserObject();
            if (entry instanceof PbxFolder) {
                registry.restoreFolderFromEntry((PbxFolder) entry);

            } else if (entry instanceof PbxFile) {
                PbxFile pbxFile = (PbxFile) entry;
                java.util.List<String> snapshots = pbxFile.snapshotsToString();
                if (snapshots.isEmpty()) {
                    setVisible(true);
                    return;
                }

                JFrame frame = new JFrame("Choose backup");
                Object option = JOptionPane.showInputDialog(frame,
                        "Choose below what backup snapshot would you like restore:", "Choose backup",
                        JOptionPane.QUESTION_MESSAGE, null, snapshots.toArray(), snapshots.get(0));

                if (option == null) {
                    setVisible(true);
                    return;
                }
                int pickedIndex = snapshots.indexOf(option.toString());
                registry.restoreFileFromEntry((PbxFile) entry, pickedIndex);
            }
            dispose();
        }
    });
    add(restoreBackupButton);

    tree.addMouseListener((OnMouseClick) e -> {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
        if (node != null) {
            PbxEntry entry = (PbxEntry) node.getUserObject();
            if ((entry instanceof PbxFolder && entry.areNativeFilesDeleted())) {
                permanentDeleteButton.setEnabled(true);
                restoreBackupButton.setEnabled(true);
                configBackupsButton.setEnabled(false);

            } else if (entry instanceof PbxFile) {
                permanentDeleteButton.setEnabled(true);
                restoreBackupButton.setEnabled(true);
                configBackupsButton.setEnabled(true);

            } else {
                permanentDeleteButton.setEnabled(false);
                restoreBackupButton.setEnabled(false);
                configBackupsButton.setEnabled(false);
            }
        }
    });

    final JLabel cancel = new JLabel(new ImageIcon(Constants.getAsset("cancel.png")));
    cancel.setLayout(null);
    cancel.setBounds(229, 390, 122, 39);
    cancel.setBackground(Color.black);
    cancel.addMouseListener((OnMouseClick) e -> dispose());
    add(cancel);

    addWindowFocusListener(new WindowFocusListener() {
        private boolean gained = false;

        @Override
        public void windowGainedFocus(WindowEvent e) {
            gained = true;
        }

        @Override
        public void windowLostFocus(WindowEvent e) {
            if (gained) {
                dispose();
            }
        }
    });

    setSize(340, 432);
    setUndecorated(true);
    getContentPane().setBackground(Color.white);
    setResizable(false);
    getRootPane().setBorder(BorderFactory.createLineBorder(new Color(100, 100, 100)));
    Utils.setComponentLocationOnCenter(this);
    setVisible(true);
}

From source file:de.dal33t.powerfolder.PowerFolder.java

/**
 * Starts a PowerFolder controller with the given command line arguments
 *
 * @param args/*www  .  j  av  a 2 s .c  om*/
 */
public static void startPowerFolder(String[] args) {

    // Touch Logger immediately to initialize handlers.
    LoggingManager.isLogToFile();

    // Default exception logger
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            e.printStackTrace();
            log.log(Level.SEVERE, "Exception in " + t + ": " + e.toString(), e);
        }
    });

    CommandLine commandLine = parseCommandLine(args);
    if (commandLine == null) {
        return;
    }

    // -l --log console log levels (severe, warning, info, fine and finer).
    if (commandLine.hasOption("l")) {
        String levelName = commandLine.getOptionValue("l");
        Level level = LoggingManager.levelForName(levelName);
        if (level != null) {
            LoggingManager.setConsoleLogging(level);
        }
    }

    if (commandLine.hasOption("s")) {
        // Server mode, suppress debug output on console
        // Logger.addExcludeConsoleLogLevel(Logger.DEBUG);
    }

    if (commandLine.hasOption("h")) {
        // Show help
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("PowerFolder", COMMAND_LINE_OPTIONS);
        return;
    }

    int rconPort = Integer.valueOf(ConfigurationEntry.NET_RCON_PORT.getDefaultValue());
    String portStr = commandLine.getOptionValue("k");
    if (StringUtils.isNotBlank(portStr)) {
        try {
            rconPort = Integer.valueOf(portStr.trim());
        } catch (Exception e) {
            log.warning("Unable to parse rcon port: " + portStr + ". " + e);
        }
    }

    boolean runningInstanceFound = RemoteCommandManager.hasRunningInstance(rconPort);

    if (commandLine.hasOption("k")) {
        if (runningInstanceFound) {
            System.out.println("Stopping " + NAME);
            // Send quit command
            RemoteCommandManager.sendCommand(rconPort, RemoteCommandManager.QUIT);
        } else {
            System.err.println("Process not running");
        }

        // stop
        return;
    }

    // set language from commandline to preferences
    if (commandLine.hasOption("g")) {
        Preferences.userNodeForPackage(Translation.class).put("locale", commandLine.getOptionValue("g"));
    }

    if (JavaVersion.systemVersion().isOpenJDK()) {
        Object[] options = { "Open Oracle home page and exit", "Exit" };

        int n = JOptionPane.showOptionDialog(null,
                "You are using OpenJDK which is unsupported.\n"
                        + "Please install the client with bundled JRE or install the Oracle JRE",
                "Unsupported JRE", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options,
                options[0]);

        if (n == 0) {
            try {
                BrowserLauncher.openURL("http://www.java.com");
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }

        return;
    }

    // The controller.
    Controller controller = Controller.createController();

    String[] files = commandLine.getArgs();
    // Parsing of command line completed

    boolean commandContainsRemoteCommands = files != null && files.length >= 1 || commandLine.hasOption("e")
            || commandLine.hasOption("r") || commandLine.hasOption("a");
    // Try to start controller
    boolean startController = !commandContainsRemoteCommands || !runningInstanceFound;
    try {
        log.info("PowerFolder v" + Controller.PROGRAM_VERSION);

        // Start controller
        if (startController) {
            controller.startConfig(commandLine);
        }

        // Send remote command if there a files in commandline
        if (files != null && files.length > 0) {
            // Parse filenames and build remote command
            StringBuilder openFilesRCommand = new StringBuilder(RemoteCommandManager.OPEN);

            for (String file : files) {
                openFilesRCommand.append(file);
                // FIXME: Add ; separator ?
            }

            // Send remote command to running PowerFolder instance
            RemoteCommandManager.sendCommand(openFilesRCommand.toString());
        }

        if (commandLine.hasOption("e")) {
            RemoteCommandManager.sendCommand(RemoteCommandManager.MAKEFOLDER + commandLine.getOptionValue("e"));
        }
        if (commandLine.hasOption("r")) {
            RemoteCommandManager
                    .sendCommand(RemoteCommandManager.REMOVEFOLDER + commandLine.getOptionValue("r"));
        }
        if (commandLine.hasOption("a")) {
            RemoteCommandManager.sendCommand(RemoteCommandManager.COPYLINK + commandLine.getOptionValue("a"));
        }
    } catch (Throwable t) {
        t.printStackTrace();
        log.log(Level.SEVERE, "Throwable", t);
        return;
    }

    // Begin monitoring memory usage.
    if (controller.isStarted() && controller.isUIEnabled()) {
        ScheduledExecutorService service = controller.getThreadPool();
        service.scheduleAtFixedRate(new MemoryMonitor(controller), 1, 1, TimeUnit.MINUTES);
    }

    // Not go into console mode if ui is open
    if (!startController) {
        if (runningInstanceFound) {
            RemoteCommandManager.sendCommand(RemoteCommandManager.SHOW_UI);
        }
        return;
    }

    System.out.println("------------ " + NAME + " " + Controller.PROGRAM_VERSION + " started ------------");

    boolean restartRequested = false;
    do {
        // Go into restart loop
        while (controller.isStarted() || controller.isShuttingDown()) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                log.log(Level.WARNING, "InterruptedException", e);
                return;
            }
        }

        restartRequested = controller.isRestartRequested();
        if (restartRequested) {
            Map<Thread, StackTraceElement[]> threads = Thread.getAllStackTraces();
            for (Thread thread : threads.keySet()) {
                if (thread.getName().startsWith("PoolThread") || thread.getName().startsWith("Reconnector")
                        || thread.getName().startsWith("ConHandler")) {
                    thread.interrupt();
                }
            }
            log.info("Restarting controller");
            System.out.println(
                    "------------ " + NAME + " " + Controller.PROGRAM_VERSION + " restarting ------------");
            controller = null;
            System.gc();
            controller = Controller.createController();
            // Start controller
            controller.startConfig(commandLine);
        }
    } while (restartRequested);
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRResultsController.java

/**
 * @param pdfFile/*from w w  w .  j a  v a 2  s  .co  m*/
 */
@Override
protected void tryToCreateFile(File pdfFile) {
    try {
        boolean success = pdfFile.createNewFile();
        if (success) {
            doseResponseController.showMessage("Pdf Report successfully created!", "Report created",
                    JOptionPane.INFORMATION_MESSAGE);
        } else {
            Object[] options = { "Yes", "No", "Cancel" };
            int showOptionDialog = JOptionPane.showOptionDialog(null,
                    "File already exists. Do you want to replace it?", "", JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE, null, options, options[2]);
            // if YES, user wants to delete existing file and replace it
            if (showOptionDialog == 0) {
                boolean delete = pdfFile.delete();
                if (!delete) {
                    return;
                }
                // if NO, returns already existing file
            } else if (showOptionDialog == 1) {
                return;
            }
        }
    } catch (IOException ex) {
        doseResponseController.showMessage("Unexpected error: " + ex.getMessage() + ".", "Unexpected error",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    try (FileOutputStream fileOutputStream = new FileOutputStream(pdfFile)) {
        // actually create PDF file
        createPdfFile(fileOutputStream);
    } catch (IOException ex) {
        doseResponseController.showMessage("Unexpected error: " + ex.getMessage() + ".", "Unexpected error",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.dmrr.asistenciasx.Horarios.java

private void jButtonReasignarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReasignarActionPerformed
    int x = jTableHorarios.getSelectedRow();
    if (x == -1) {
        JOptionPane.showMessageDialog(this, "Seleccione un profesor primero", "Datos incompletos",
                JOptionPane.WARNING_MESSAGE);
        return;// w  w w. j a v a2  s . c o m
    }
    Integer idCurso = Integer.parseInt((String) jTableHorarios.getValueAt(jTableHorarios.getSelectedRow(), 0));
    String nombreProfesor = (String) jTableHorarios.getValueAt(jTableHorarios.getSelectedRow(), 2);
    ventanaReasignarCurso = new HorariosReasignarPantallaListaDeProfesores(idCurso, nombreProfesor, this);
    ventanaReasignarCurso.setVisible(true);
}