Example usage for javax.swing JOptionPane selectInitialValue

List of usage examples for javax.swing JOptionPane selectInitialValue

Introduction

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

Prototype

public void selectInitialValue() 

Source Link

Document

Requests that the initial value be selected, which will set focus to the initial value.

Usage

From source file:eu.delving.sip.base.VisualFeedback.java

public static boolean askOption(JDesktopPane desktop, Object message, String title, int optionType,
        int messageType) {
    JOptionPane pane = new JOptionPane(message, messageType, optionType, null, null, null);
    pane.putClientProperty(new Object(), Boolean.TRUE);
    JDialog frame = pane.createDialog(desktop, title);
    pane.selectInitialValue();
    frame.setVisible(true);/*w  w w  .  j  a v a 2  s .  c o m*/
    acquireFocus();
    Object selectedValue = pane.getValue();
    return selectedValue != null && selectedValue instanceof Integer && (Integer) selectedValue == YES_OPTION;
}

From source file:net.menthor.editor.v2.util.Util.java

/** Helper method for constructing an always-on-top modal dialog. */
public static Object show(String title, int type, Object message, Object[] options, Object initialOption) {
    if (options == null) {
        options = new Object[] { "Ok" };
        initialOption = "Ok";
    }/*from   w  ww  .  java  2 s  .c om*/
    JOptionPane p = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, options, initialOption);
    p.setInitialValue(initialOption);
    JDialog d = p.createDialog(null, title);
    p.selectInitialValue();
    d.setAlwaysOnTop(true);
    d.setVisible(true);
    d.dispose();
    return p.getValue();
}

From source file:eu.delving.sip.base.VisualFeedback.java

public static String askQuestion(JDesktopPane desktop, String question, Object initialSelectionValue) {
    final JOptionPane pane = new JOptionPane(question, QUESTION_MESSAGE, OK_CANCEL_OPTION, null, null, null);
    pane.putClientProperty(new Object(), Boolean.TRUE);
    pane.setWantsInput(true);/* www. ja v  a  2s  .  c o  m*/
    pane.setInitialSelectionValue(initialSelectionValue);
    JDialog frame = pane.createDialog(desktop, "Question");
    pane.selectInitialValue();
    frame.setVisible(true);
    acquireFocus();
    Object value = pane.getInputValue();
    return value == UNINITIALIZED_VALUE ? null : (String) value;
}