Confirm Dialog in Swing
import javax.swing.JOptionPane; public class JOptionDialog { public static void main(String[] args) { JOptionPane.showConfirmDialog(null, "Are you sure?", "Example 4", JOptionPane.YES_NO_CANCEL_OPTION); } }
Finally, let’s use a JOptionPane constructor and place the new pane inside a regular Swing container. This is a strange thing to do, but it’s perfectly valid
import java.awt.*; import javax.swing.*; public class JOptionDialog { public static void main(String[] args) { JFrame f = new JFrame( ); Container c = f.getContentPane( ); c.setLayout(new BorderLayout( )); JOptionPane op = new JOptionPane("Stop!", JOptionPane.WARNING_MESSAGE); JPanel p = new JPanel(new FlowLayout( )); p.add(op); c.add(p); c.add(new JLabel("Example 6", JLabel.CENTER), BorderLayout.NORTH); f.setSize(200,200); f.setVisible(true); } }