The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > JFrame, JWindow, JDialog  [6 examples]

e737. Showing a Dialog Box

    // Modal dialog with OK button
    String message = "Line1\nLine2";
    JOptionPane.showMessageDialog(frame, message);
    
    // Modal dialog with yes/no button
    int answer = JOptionPane.showConfirmDialog(frame, message);
    if (answer == JOptionPane.YES_OPTION) {
        // User clicked YES.
    } else if (answer == JOptionPane.NO_OPTION) {
        // User clicked NO.
    }
    
    // Modal dialog with OK/cancel and a text field
    String text = JOptionPane.showInputDialog(frame, message);
    if (text == null) {
        // User clicked cancel
    }

 Related Examples
e733. Creating a JFrame
e734. Exiting an Application When a JFrame Is Closed
e735. Disabling the Close Button on a JFrame
e736. Creating a Borderless Window
e738. Getting the JFrame of a Component

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.