javax.swing.JOptionPane.setWantsInput()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中javax.swing.JOptionPane.setWantsInput()方法的一些代码示例,展示了JOptionPane.setWantsInput()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JOptionPane.setWantsInput()方法的具体详情如下:
包路径:javax.swing.JOptionPane
类名称:JOptionPane
方法名:setWantsInput

JOptionPane.setWantsInput介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

JOptionPane pane = new JOptionPane("Message", JOptionPane.QUESTION_MESSAGE,
    JOptionPane.OK_CANCEL_OPTION, null, null, null);
pane.setWantsInput(true);
JDialog dialog = pane.createDialog(null, "Title");
dialog.setLocation(0, 0);
dialog.setVisible(true);

String str = (String) pane.getInputValue();

代码示例来源:origin: stackoverflow.com

public class LocaleOptionPane extends JFrame {

  public static void main(String[] args) {

    new LocaleOptionPane();
  }

  LocaleOptionPane() {

    Locale loc = new Locale("iw", "IL");
    String message = "<html><b><font color=\"#8F0000\" size=\"10\" face=\"Ariel\">" + "הכנס סטטוס חדש: " + "</font></p></html>";

    setVisible(true);

    JOptionPane pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    pane.setWantsInput(true);

    JDialog dialog = pane.createDialog(this, UIManager.getString("OptionPane.inputDialogTitle", loc));
    dialog.getInputContext().selectInputMethod(loc); // pane.getInputContext... also works
    dialog.setVisible(true);
    dialog.dispose();

    String response = (String) pane.getInputValue();
    if (response == JOptionPane.UNINITIALIZED_VALUE)
      System.out.println("aborted");
    else
      System.out.println(response);
  }
}

代码示例来源:origin: stackoverflow.com

public class JEnhancedOptionPane extends JOptionPane {
  public static String showInputDialog(final Object message, final Object[] options)
      throws HeadlessException {
    final JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE,
                         OK_CANCEL_OPTION, null,
                         options, null);
    pane.setWantsInput(true);
    pane.setComponentOrientation((getRootFrame()).getComponentOrientation());
    pane.setMessageType(QUESTION_MESSAGE);
    pane.selectInitialValue();
    final String title = UIManager.getString("OptionPane.inputDialogTitle", null);
    final JDialog dialog = pane.createDialog(null, title);
    dialog.setVisible(true);
    dialog.dispose();
    final Object value = pane.getInputValue();
    return (value == UNINITIALIZED_VALUE) ? null : (String) value;
  }
}

代码示例来源:origin: stackoverflow.com

public class JEnhancedOptionPane extends JOptionPane {
public static String showInputDialog(final Object message, final Object[] options)
    throws HeadlessException {
  final JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE,
                       OK_CANCEL_OPTION, null,
                       options, null);
  pane.setWantsInput(true);
  pane.setComponentOrientation((getRootFrame()).getComponentOrientation());
  pane.setMessageType(QUESTION_MESSAGE);
  pane.selectInitialValue();
  final String title = UIManager.getString("OptionPane.inputDialogTitle", null);
  final JDialog dialog = pane.createDialog(null, title);
  dialog.setVisible(true);
  dialog.dispose();
  final Object value = pane.getInputValue();
  return (value == UNINITIALIZED_VALUE) ? null : (String) value;
}
}

代码示例来源:origin: stackoverflow.com

final JOptionPane optionPane = new JOptionPane("What is your first name?",
  JOptionPane.QUESTION_MESSAGE);
optionPane.setWantsInput(true);

Action accept = new AbstractAction("OK") {
  private static final long serialVersionUID = 1;
  public void actionPerformed(ActionEvent event) {
    Object value = optionPane.getInputValue();
    if (value != null && !value.toString().isEmpty()) {
      // This dismisses the JOptionPane dialog.
      optionPane.setValue(JOptionPane.OK_OPTION);
    }
  }
};

Object acceptButton = new JButton(accept);
optionPane.setOptions(new Object[] { acceptButton, "Cancel" });
optionPane.setInitialValue(acceptButton);

// Waits until dialog is dismissed.
optionPane.createDialog(null, "First Name").setVisible(true);

if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(optionPane.getValue())) {
  // User canceled dialog.
  return;
}

String fn = optionPane.getInputValue().toString();

代码示例来源:origin: stackoverflow.com

public class Main {

  public static List<Component> getAllComponents(final Container c) {
    Component[] comps = c.getComponents();
    List<Component> compList = new ArrayList<Component>();
    for (Component comp : comps) {
      compList.add(comp);
      if (comp instanceof Container)
        compList.addAll(getAllComponents((Container) comp));
    }
    return compList;
  }

  public static void main(String[] args) {
    JOptionPane optionPane = new JOptionPane();
    optionPane.setMessage("What's your name?");
    optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE);
    optionPane.setWantsInput(true);
    JDialog dialog = optionPane.createDialog("Simple Question");
    for (Component c : getAllComponents(dialog)) {
     if (c instanceof JTextField) {
       c.setToolTipText("I'm a tooltip!");
     }
    }
    dialog.setVisible(true);
    dialog.dispose();
  }
}

代码示例来源:origin: org.xworker/xworker_core

comp.setWantsInput(wantsInput);

代码示例来源:origin: stackoverflow.com

import javax.swing.*;

public class OptionPaneLocation 
{   
  private void createAndDisplayGUI()
  {       
    JOptionPane optionPane = new JOptionPane("Its me"
                  , JOptionPane.PLAIN_MESSAGE
                  , JOptionPane.DEFAULT_OPTION
                  , null, null, "Please ENTER your NAME here");
    optionPane.setWantsInput(true);             
    JDialog dialog = optionPane.createDialog(null, "TEST");
    dialog.setLocation(10, 20);
    dialog.setVisible(true);
    System.out.println(optionPane.getInputValue());
  }

  public static void main(String... args)
  {
    Runnable runnable = new Runnable()
    {
      public void run()
      {
        new OptionPaneLocation().createAndDisplayGUI();
      }
    };
    SwingUtilities.invokeLater(runnable);
  }
}

代码示例来源:origin: jaltekruse/OpenNotebook

private String createPopupBelowCurrObject(String message, String defaultInput) {
  MathObject currFocused = this.getCurrentDocViewer().getFocusedObject();
  PointInDocument ptInDoc = new PointInDocument(
      // TODO - HAX - fix this
      this.getCurrentDocViewer().getDoc().getPageIndex(currFocused.getParentPage()),
      currFocused.getxPos(), currFocused.getyPos() + currFocused.getHeight());
  JOptionPane optionPane = new JOptionPane(message
      , JOptionPane.PLAIN_MESSAGE
      , JOptionPane.DEFAULT_OPTION
      , null, null, defaultInput);
  optionPane.setWantsInput(true);
  optionPane.setInitialSelectionValue(defaultInput);
  JDialog dialog = optionPane.createDialog(this, "");
  Point p = getCurrentDocViewer().docPt2AbsoluteScreenPos(ptInDoc);
  optionPane.selectInitialValue();
  dialog.setBounds((int) p.getX(), (int)p.getY() + 15, 250, 200);
  dialog.setVisible(true);
  dialog.dispose();
  String result = (String) optionPane.getInputValue();
  return result.equals("uninitializedValue") ? null : result;
}

代码示例来源:origin: stackoverflow.com

pane.setWantsInput(true);
pane.setSelectionValues(choices);
pane.setInitialSelectionValue(choices[0]);

代码示例来源:origin: stackoverflow.com

import javax.swing.*;
import java.awt.*;

public class MyOptionPane {

  static Object showInputDialog(Object f,  Object message, String title, int messageType,
                 Icon ico, Object[] options, Object initValue) {

    JOptionPane pane = new JOptionPane(message, messageType, JOptionPane.OK_CANCEL_OPTION,
        ico, options,  initValue);

    JDialog dialog = pane.createDialog((Component) f, title);
    if (!dialog.isResizable()) {
      dialog.setResizable(true);
    }
    pane.setInitialSelectionValue(pane.getInitialValue()); // set it
    pane.setWantsInput(true);

    dialog.pack();
    dialog.setVisible(true);

    return pane.getInputValue();
  }
}

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

null, null);
pane.setWantsInput(true);
pane.setSelectionValues(selectionValues);
pane.setInitialSelectionValue(initialSelectionValue);

相关文章