List of usage examples for javax.swing JOptionPane createDialog
public JDialog createDialog(Component parentComponent, String title) throws HeadlessException
JDialog
wrapping this
centered on the parentComponent
in the parentComponent
's frame. 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 .j ava 2 s .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:AskingQuestionDialog.java
public static void main(String argv[]) { JOptionPane pane = new JOptionPane("To be or not to be ?\nThat is the question."); Object[] options = new String[] { "To be", "Not to be" }; pane.setOptions(options);/* w ww. j ava2s . c om*/ JDialog dialog = pane.createDialog(new JFrame(), "Dilaog"); dialog.show(); Object obj = pane.getValue(); int result = -1; for (int k = 0; k < options.length; k++) if (options[k].equals(obj)) result = k; System.out.println("User's choice: " + result); }
From source file:Main.java
public static void main(String[] args) { String[] options = { "Button 1", "Button 2", "Button 3" }; JOptionPane myOptionPane = new JOptionPane("Heres a test message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[2]); JDialog myDialog = myOptionPane.createDialog(null, "My Test"); myDialog.setModal(true);//from w w w . jav a2s. c o m inactivateOption(myDialog, options[1]); myDialog.setVisible(true); Object result = myOptionPane.getValue(); System.out.println("result: " + result); }
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 . j av a 2 s . co m JDialog dialog = optionPane.createDialog(null, "TEST"); dialog.setLocation(10, 20); dialog.setVisible(true); System.out.println(optionPane.getInputValue()); }
From source file:JOptionPaneDemonstrationLocalized.java
public static void main(String[] argv) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font unicodeFont = new Font("LucidaSans", Font.PLAIN, 12); ResourceBundle bundle = ResourceBundle.getBundle("JOptionPaneResources", Locale.getDefault()); String[] textMessages = new String[3]; textMessages[0] = bundle.getString("Yes"); textMessages[1] = bundle.getString("No"); textMessages[2] = bundle.getString("Cancel"); JOptionPane jop = new JOptionPane(bundle.getString("MessageText"), JOptionPane.ERROR_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, textMessages); JDialog jopDialog = jop.createDialog(null, bundle.getString("TitleText")); jop.setFont(unicodeFont);//from www . jav a 2s . c o m jopDialog.setVisible(true); Object userSelection = jop.getValue(); }
From source file:MainClass.java
public static void main(String[] a) { JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("Set Message"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); optionPane.setOptions(new Object[] { new JButton("Button") }); JDialog dialog = optionPane.createDialog(null, "Icon/Text Button"); dialog.setVisible(true);/*from w w w . jav a 2 s . com*/ }
From source file:ManualDisplayPopup.java
public static void main(String args[]) { JFrame frame = new JFrame("NoButton Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Ask"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); JOptionPane optionPane = new JOptionPane("Continue printing?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); JDialog dialog = optionPane.createDialog(source, "Manual Creation"); dialog.show();/*from w w w .j a v a 2 s . c om*/ int selection = OptionPaneUtils.getSelection(optionPane); System.out.println(selection); } }; button.addActionListener(actionListener); Container contentPane = frame.getContentPane(); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
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 w w w . ja va2 s . c o m*/ System.out.println("Input: " + optionPane.getInputValue()); }
From source file:AddingButtonWithActionListener.java
public static void main(String[] a) { JFrame frame = new JFrame(); JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("I got an icon and a text label"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); Icon icon = new ImageIcon("yourFile.gif"); JButton jButton = getButton(optionPane, "OK", icon); optionPane.setOptions(new Object[] { jButton }); JDialog dialog = optionPane.createDialog(frame, "Icon/Text Button"); dialog.setVisible(true);/* ww w. j av a2 s. co m*/ }
From source file:MessagePopup.java
public static void main(String args[]) { JFrame frame = new JFrame("Message Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Pop it"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); /*/*from www . java2s . com*/ * // String msg = "this is a really long message this is a * really long message this is a really long message this is a * really long message this is a really long message this is a * really long message this is a really long message"; String * msg = " <html>this is a really long message <br> this is a * really long message this is a really long message this is a * really long message this is a really long message this is a * really long message this is a really long message"; * JOptionPane.showMessageDialog(source, msg); JOptionPane * optionPane = OptionPaneUtils.getNarrowOptionPane(72); * optionPane.setMessage(msg); * optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); * JDialog dialog = optionPane.createDialog(source, "Width 72"); * dialog.show(); int selection = * OptionPaneUtils.getSelection(optionPane); * JOptionPane.showMessageDialog(source, msg); String * multiLineMsg[] = {"Hello", "World"}; * JOptionPane.showMessageDialog(source, multiLineMsg); * * Object complexMsg[] = {"Above Message", new * DiamondIcon(Color.red), new JButton ("Hello"), new JSlider(), * new DiamondIcon(Color.blue), "Below Message"}; * JOptionPane.showInputDialog(source, complexMsg); JOptionPane * optionPane = new JOptionPane(); JSlider slider = * OptionPaneUtils.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(source, "My * Slider"); dialog.show(); System.out.println ("Input: " + * optionPane.getInputValue()); */ JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("I got an icon and a text label"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); Icon icon = new DiamondIcon(Color.blue); JButton jButton = OptionPaneUtils.getButton(optionPane, "OK", icon); optionPane.setOptions(new Object[] { jButton }); JDialog dialog = optionPane.createDialog(source, "Icon/Text Button"); dialog.show(); } }; button.addActionListener(actionListener); Container contentPane = frame.getContentPane(); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }