List of usage examples for javax.swing JOptionPane setWantsInput
@BeanProperty(preferred = true, description = "Flag which allows the user to input a value.") public void setWantsInput(boolean newValue)
wantsInput
property. From source file:DualModal.java
public static void main(String args[]) { final JFrame frame1 = new JFrame("Left"); final JFrame frame2 = new JFrame("Right"); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Left"); JButton button2 = new JButton("Right"); frame1.add(button1);/*from w w w . jav a 2s . c o m*/ frame2.add(button2); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { JButton source = (JButton) e.getSource(); JOptionPane pane = new JOptionPane("New label", JOptionPane.QUESTION_MESSAGE); pane.setWantsInput(true); JDialog dialog = pane.createDialog(frame2, "Enter Text"); // dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL); dialog.setVisible(true); String text = (String) pane.getInputValue(); if (!JOptionPane.UNINITIALIZED_VALUE.equals(text) && text.trim().length() > 0) { source.setText(text); } } }; button1.addActionListener(listener); button2.addActionListener(listener); frame1.setBounds(100, 100, 200, 200); frame1.setVisible(true); frame2.setBounds(400, 100, 200, 200); frame2.setVisible(true); }
From source file:Main.java
public static void main(String... args) { 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);/* w w w . j a va 2 s. com*/ dialog.setVisible(true); System.out.println(optionPane.getInputValue()); }
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); pane.setInitialSelectionValue(initialSelectionValue); JDialog frame = pane.createDialog(desktop, "Question"); pane.selectInitialValue();// w ww . j a v a2s . com frame.setVisible(true); acquireFocus(); Object value = pane.getInputValue(); return value == UNINITIALIZED_VALUE ? null : (String) value; }