List of usage examples for javax.swing JOptionPane getInputValue
public Object getInputValue()
wantsInput
is 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);/* w w w . ja v a 2 s . c om*/ JDialog dialog = optionPane.createDialog(null, "TEST"); dialog.setLocation(10, 20); dialog.setVisible(true); System.out.println(optionPane.getInputValue()); }
From source file:JSliderOnJOptionPane.java
public static void main(final String[] args) { JFrame parent = new JFrame(); JOptionPane optionPane = new JOptionPane(); JSlider slider = getSlider(optionPane); optionPane.setMessage(new Object[] { "Select a value: ", slider }); optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE); optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION); JDialog dialog = optionPane.createDialog(parent, "My Slider"); dialog.setVisible(true);/*from www . java2 s . co m*/ System.out.println("Input: " + optionPane.getInputValue()); }
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);//ww w . j a v 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: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);/*from www . ja va2 s . 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; }