Example usage for javax.swing JOptionPane showInputDialog

List of usage examples for javax.swing JOptionPane showInputDialog

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType,
        Icon icon, Object[] selectionValues, Object initialSelectionValue) throws HeadlessException 

Source Link

Document

Prompts the user for input in a blocking dialog where the initial selection, possible selections, and all other options can be specified.

Usage

From source file:com.swg.parse.docx.OpenWord.java

/***
 * Allows the user to enter the version of the document in question
 *///from   ww  w  .  j  a  v a 2  s .c  om
private void VersionSlector() {

    Object[] possibilities = { 0, 1, 2 };

    version = (int) JOptionPane.showInputDialog(WindowManager.getDefault().getMainWindow(),
            "please select the version of the form", "Form Version", JOptionPane.PLAIN_MESSAGE, icon,
            possibilities, 0);

}

From source file:cz.lidinsky.editor.Editor.java

/**
 *
 *//* ww w .j av a2s.  co m*/
public String letSelectComponent() {
    // get array of component names
    Collection<String> componentNames = ComponentFactory.getInstance().getComponentList();
    String[] componentNamesArray = componentNames.toArray(new String[componentNames.size()]);
    System.out.println(componentNamesArray.toString());
    // show input dialog
    String selected = (String) JOptionPane.showInputDialog(frame, "Select component", "Components",
            JOptionPane.QUESTION_MESSAGE, null, componentNamesArray, componentNamesArray[0]);
    return selected;
}

From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

public static String showInputDialog(Component parent, String title, String message) {
    Object[] possibilities = null;
    String s = (String) JOptionPane.showInputDialog(parent, message, title, JOptionPane.PLAIN_MESSAGE, null,
            possibilities, null);//w  ww  .ja  va2s  . c o  m

    return StringUtils.isNotBlank(s) ? s : null;
}

From source file:cz.lidinsky.editor.Editor.java

/**
 *
 *///from   ww w . j a v  a 2s  . com
protected String letSelectChanger() {
    // get array of changer names
    String[] changerNames = ChangerFactory.getInstance().getList();
    // show input dialog
    String selected = (String) JOptionPane.showInputDialog(frame, "Select changer", "Changers",
            JOptionPane.QUESTION_MESSAGE, null, changerNames, changerNames[0]);
    return selected;
}

From source file:net.sf.jabref.exporter.SaveDatabaseAction.java

private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException {
    SaveSession session;/*from   w w w  . jav  a2s.co m*/
    frame.block();
    try {
        SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs)
                .withEncoding(encoding);
        BibDatabaseWriter databaseWriter = new BibDatabaseWriter();
        if (selectedOnly) {
            session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), prefs,
                    panel.getSelectedEntries());

        } else {
            session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs);

        }
        panel.registerUndoableChanges(session);

    } catch (UnsupportedCharsetException ex2) {
        JOptionPane.showMessageDialog(frame,
                Localization.lang("Could not save file.") + Localization
                        .lang("Character encoding '%0' is not supported.", encoding.displayName()),
                Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");
    } catch (SaveException ex) {
        if (ex == SaveException.FILE_LOCKED) {
            throw ex;
        }
        if (ex.specificEntry()) {
            // Error occured during processing of
            // be. Highlight it:
            int row = panel.mainTable.findEntry(ex.getEntry());
            int topShow = Math.max(0, row - 3);
            panel.mainTable.setRowSelectionInterval(row, row);
            panel.mainTable.scrollTo(topShow);
            panel.showEntry(ex.getEntry());
        } else {
            LOGGER.error("Problem saving file", ex);
        }

        JOptionPane.showMessageDialog(frame,
                Localization.lang("Could not save file.") + ".\n" + ex.getMessage(),
                Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");

    } finally {
        frame.unblock();
    }

    boolean commit = true;
    if (!session.getWriter().couldEncodeAll()) {
        FormBuilder builder = FormBuilder.create()
                .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref"));
        JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
        ta.setEditable(false);
        builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:",
                session.getEncoding().displayName())).xy(1, 1);
        builder.add(ta).xy(3, 1);
        builder.add(Localization.lang("What do you want to do?")).xy(1, 3);
        String tryDiff = Localization.lang("Try different encoding");
        int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save database"),
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
                new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff);

        if (answer == JOptionPane.NO_OPTION) {
            // The user wants to use another encoding.
            Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"),
                    Localization.lang("Save database"), JOptionPane.QUESTION_MESSAGE, null,
                    Encodings.ENCODINGS_DISPLAYNAMES, encoding);
            if (choice == null) {
                commit = false;
            } else {
                Charset newEncoding = Charset.forName((String) choice);
                return saveDatabase(file, selectedOnly, newEncoding);
            }
        } else if (answer == JOptionPane.CANCEL_OPTION) {
            commit = false;
        }

    }

    try {
        if (commit) {
            session.commit(file);
            panel.setEncoding(encoding); // Make sure to remember which encoding we used.
        } else {
            session.cancel();
        }
    } catch (SaveException e) {
        int ans = JOptionPane.showConfirmDialog(null,
                Localization.lang("Save failed during backup creation") + ". "
                        + Localization.lang("Save without backup?"),
                Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            session.setUseBackup(false);
            session.commit(file);
            panel.setEncoding(encoding);
        } else {
            commit = false;
        }
    }

    return commit;
}

From source file:net.sf.jabref.gui.exporter.SaveDatabaseAction.java

private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException {
    SaveSession session;//from  ww  w  .  j  a v  a 2  s .co  m
    frame.block();
    try {
        SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs)
                .withEncoding(encoding);
        BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new);
        if (selectedOnly) {
            session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(),
                    panel.getSelectedEntries(), prefs);
        } else {
            session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs);

        }
        panel.registerUndoableChanges(session);

    } catch (UnsupportedCharsetException ex2) {
        JOptionPane.showMessageDialog(frame,
                Localization.lang("Could not save file.") + Localization
                        .lang("Character encoding '%0' is not supported.", encoding.displayName()),
                Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");
    } catch (SaveException ex) {
        if (ex == SaveException.FILE_LOCKED) {
            throw ex;
        }
        if (ex.specificEntry()) {
            // Error occured during processing of
            // be. Highlight it:
            int row = panel.getMainTable().findEntry(ex.getEntry());
            int topShow = Math.max(0, row - 3);
            panel.getMainTable().setRowSelectionInterval(row, row);
            panel.getMainTable().scrollTo(topShow);
            panel.showEntry(ex.getEntry());
        } else {
            LOGGER.error("Problem saving file", ex);
        }

        JOptionPane.showMessageDialog(frame,
                Localization.lang("Could not save file.") + ".\n" + ex.getMessage(),
                Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");

    } finally {
        frame.unblock();
    }

    boolean commit = true;
    if (!session.getWriter().couldEncodeAll()) {
        FormBuilder builder = FormBuilder.create()
                .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref"));
        JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
        ta.setEditable(false);
        builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:",
                session.getEncoding().displayName())).xy(1, 1);
        builder.add(ta).xy(3, 1);
        builder.add(Localization.lang("What do you want to do?")).xy(1, 3);
        String tryDiff = Localization.lang("Try different encoding");
        int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save database"),
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
                new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff);

        if (answer == JOptionPane.NO_OPTION) {
            // The user wants to use another encoding.
            Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"),
                    Localization.lang("Save database"), JOptionPane.QUESTION_MESSAGE, null,
                    Encodings.ENCODINGS_DISPLAYNAMES, encoding);
            if (choice == null) {
                commit = false;
            } else {
                Charset newEncoding = Charset.forName((String) choice);
                return saveDatabase(file, selectedOnly, newEncoding);
            }
        } else if (answer == JOptionPane.CANCEL_OPTION) {
            commit = false;
        }

    }

    try {
        if (commit) {
            session.commit(file.toPath());
            panel.getBibDatabaseContext().getMetaData().setEncoding(encoding); // Make sure to remember which encoding we used.
        } else {
            session.cancel();
        }
    } catch (SaveException e) {
        int ans = JOptionPane.showConfirmDialog(null,
                Localization.lang("Save failed during backup creation") + ". "
                        + Localization.lang("Save without backup?"),
                Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            session.setUseBackup(false);
            session.commit(file.toPath());
            panel.getBibDatabaseContext().getMetaData().setEncoding(encoding);
        } else {
            commit = false;
        }
    }

    return commit;
}

From source file:me.timothy.ddd.DrunkDuckDispatch.java

License:asdf

/**
 * Gets the OS type, prompts the user for a choice if it cannot be determined.
 * //  w  w  w .ja  va  2 s .com
 * @return the os
 */
private static String getOS() {
    String envOS = System.getProperty("os.name").toLowerCase();
    System.out.println(envOS);
    if (envOS.contains("win"))
        return "windows";
    else if (envOS.contains("mac"))
        return "macosx";
    else if (envOS.contains("nix"))
        return "linux";
    else if (envOS.contains("sunos"))
        return "solaris";

    String[] os = new String[] { "Windows", "Linux", "MacOSX", "Solaris" };
    String choice = (String) JOptionPane.showInputDialog(null,
            "Your OS could not be detected, please choose from the available options below", "OS Picker",
            JOptionPane.QUESTION_MESSAGE, null, os, os[1]);
    if (choice == null)
        System.exit(0);
    return choice.toLowerCase();
}

From source file:lu.fisch.moenagade.model.Project.java

public BloxsClass addEntity() {
    String name = "";
    boolean result;

    do {//from   w  ww . jav a  2  s .c  om
        name = (String) JOptionPane.showInputDialog(frame, "Please enter the entitie's name.", "Add entity",
                JOptionPane.PLAIN_MESSAGE, null, null, name);

        if (name == null)
            return null;

        result = true;

        // check if name is OK
        Matcher matcher = Pattern.compile("^[a-zA-Z_$][a-zA-Z_$0-9]*$").matcher(name);
        boolean found = matcher.find();
        if (!found) {
            result = false;
            JOptionPane.showMessageDialog(frame, "Please chose a valid name.", "Error",
                    JOptionPane.ERROR_MESSAGE, Moenagade.IMG_ERROR);
        }
        // check if name is unique
        else if (entities.containsKey(name) || worlds.containsKey(name)) {
            result = false;
            JOptionPane.showMessageDialog(frame, "This name is not unique.", "Error", JOptionPane.ERROR_MESSAGE,
                    Moenagade.IMG_ERROR);
        }
        // check internal name
        else if (name.trim().equals("Entity")) {
            result = false;
            JOptionPane.showMessageDialog(frame,
                    "The name \"Entity\" is already internaly\nused and thus not allowed!", "Error",
                    JOptionPane.ERROR_MESSAGE, Moenagade.IMG_ERROR);
        } else if (name.charAt(0) != name.toUpperCase().charAt(0)) {
            result = false;
            JOptionPane.showMessageDialog(frame, "The name should start with a capital letter.", "Error",
                    JOptionPane.ERROR_MESSAGE, Moenagade.IMG_ERROR);
        } else {
            Entity entity = new Entity(name);
            entity.setProject(this);
            selected = entity;
            entities.put(name, entity);

            return entity;
        }
    } while (!result);

    return null;
}

From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java

private void createOptionPaneForIsoDate(int row, int column) {
    DateNormalization dateNormalization = new DateNormalization();
    String currentResult = (String) dm.getValueAt(row, column);
    String explanation = "'" + currentResult + "' " + labels.getString("dateConversion.notValidDate") + "\n"
            + labels.getString("dateConversion.enterCorrectIsoDate") + "\n"
            + labels.getString("dateConversion.validValues");
    String result;/*  w  w w.j  a v a  2  s. c  o  m*/
    do {
        result = (String) JOptionPane.showInputDialog(getContentPane(), explanation,
                labels.getString("dateConversion.header"), JOptionPane.QUESTION_MESSAGE, Utilities.icon, null,
                null);
        if (result == null)
            break;
    } while (dateNormalization.checkForNormalAttribute(result) == null);
    if (result != null) {
        dm.setValueAt(result, row, column);
        dm.fireTableCellUpdated(row, column);
    } else {
        dm.setValueAt("", row, column);
        dm.fireTableCellUpdated(row, column);
    }
}

From source file:Debrief.Tools.FilterOperations.ShowTimeVariablePlot3.java

private WatchableList getPrimary() {
    WatchableList res = null;//from  w  w w . j  a v a  2 s . c o m

    // check we have some tracks selected
    if (_theTracks != null) {
        final Object[] opts = new Object[_theTracks.size()];
        _theTracks.copyInto(opts);
        res = (WatchableList) JOptionPane.showInputDialog(null,
                "Which is the primary track?" + System.getProperty("line.separator")
                        + "  (to be used as the subject of calculations)",
                "Show Time Variable Plot", JOptionPane.QUESTION_MESSAGE, null, opts, null);
    } else {
        MWC.GUI.Dialogs.DialogFactory.showMessage("Track Selector", "Please select one or more tracks");
    }
    return res;
}