Example #1
0
  /**
   * Prompts the user for input in a sheet where the initial selection, possible selections, and all
   * other options can be specified. The user will able to choose from {@code selectionValues},
   * where {@code null} implies the user can input whatever they wish, usually by means of a {@code
   * JTextField}. {@code initialSelectionValue} is the initial value to prompt the user with. It is
   * up to the UI to decide how best to represent the {@code selectionValues}, but usually a {@code
   * JComboBox}, {@code JList}, or {@code JTextField} will be used.
   *
   * @param parentComponent the parent {@code Component} for the dialog
   * @param message the {@code Object} to display
   * @param messageType the type of message to be displayed: {@code JOptionPane.ERROR_MESSAGE},
   *     {@code JOptionPane.INFORMATION_MESSAGE}, {@code JOptionPane.WARNING_MESSAGE}, {@code
   *     JOptionPane.QUESTION_MESSAGE}, or {@code JOptionPane.PLAIN_MESSAGE}
   * @param icon the {@code Icon} image to display
   * @param selectionValues an array of {@code Object}s that gives the possible selections
   * @param initialSelectionValue the value used to initialize the input field
   * @param listener The listener for SheetEvents.
   */
  public static void showInputSheet(
      Component parentComponent,
      Object message,
      int messageType,
      Icon icon,
      Object[] selectionValues,
      Object initialSelectionValue,
      SheetListener listener) {

    JOptionPane pane =
        new JOptionPane(message, messageType, JOptionPane.OK_CANCEL_OPTION, icon, null, null);

    pane.setWantsInput(true);
    pane.setSelectionValues(selectionValues);
    pane.setInitialSelectionValue(initialSelectionValue);
    pane.setComponentOrientation(
        ((parentComponent == null) ? JOptionPane.getRootFrame() : parentComponent)
            .getComponentOrientation());

    int style = styleFromMessageType(messageType);
    JSheet sheet = createSheet(pane, parentComponent, style);

    pane.selectInitialValue();

    /*
    sheet.addWindowListener(new WindowAdapter() {
    public void windowClosed(WindowEvent evt) {
    sheet.dispose();
    }
    });*/
    sheet.addSheetListener(listener);
    sheet.show();
    sheet.toFront();
  }