1

I'm trying to write a program to open up several different JOptionPanes with different messages in each of them.
I have searched, but couldn't find how to do it.
It was fairly simple to have the windows open in order, but I couldn't have them pop up at the same time, appearing to the user together.
This is what I have right now:

    import java.util.*;
    import javax.swing.*;

    public class HelloTest 
    {
        public static void main(String[] args) 
        {   
            JOptionPane.showMessageDialog(null, "Window1");
            JOptionPane.showMessageDialog(null, "Window2");
        }
     }

Help would be appreciated! Thanks!

1 Answers1

1

By default all JOptionPane utility methods produce modal dialogs.

You can however create dialogs manually and call setModal(false) on the created JDialog instance...

public static void main(String[] args) throws Exception {
    JOptionPane pane1 = new JOptionPane();
    JDialog dialog1 = pane1.createDialog(null, "Window1");
    dialog1.setModal(false);
    dialog1.setVisible(true);

    JOptionPane pane2 = new JOptionPane();
    JDialog dialog2 = pane2.createDialog(null, "Window2");
    dialog2.setModal(false);
    dialog2.setVisible(true);
}
Adam
  • 35,919
  • 9
  • 100
  • 137