Move from JFrame to JDialog

1

I've created a frame of this genre:

Butsinceitwastoshowthattheclientwashavingtroubleconnectingtoaserver,itwasbettertoswitchtoJDialog

Problem:IcannotgetJDialogvisible

Code:

publicclassWaitingJoptionextendsJDialog{//seforJFramefuncionadireitopublicWaitingJoption(){initUI();}privatevoidinitUI(){setTitle("Agurde pff...");
        setUndecorated(true);
        JPanel pane= new JPanel();
        JPanel pane1= new JPanel();

        pane.setLayout(new GridBagLayout());
        pane1 = new Surface();

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.VERTICAL;
        c.ipady = 80;      //make this component tall
        c.ipadx = 80;
        c.weightx = 0.0;
        c.gridwidth = 3;
        c.gridx = 0;
        c.gridy = 0;
        pane.add(pane1, c);


        JLabel labe = new JLabel("O cliente está a tentar connectar com o servidor...");
        c.fill = GridBagConstraints.VERTICAL;
        c.ipady = 40;      //make this component tall
        c.weightx = 0.0;
        c.gridwidth = 3;
        c.gridx = 0;
        c.gridy = 1;
        pane.add(labe, c);


        getContentPane().add(pane);
        setSize(300, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
    }

    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                WaitingJoption wt = new WaitingJoption();
                wt.setVisible(true);
            }
        });
    }
}
    
asked by anonymous 03.11.2014 / 16:16

1 answer

2

In the code in question a IllegalArgumentException is thrown on line 50.

This is because you are using an illegal constant for a JDialog in the following snippet:

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

The constants that can be used in this method for JDialog are: DO_NOTHING_ON_CLOSE , HIDE_ON_CLOSE , or DISPOSE_ON_CLOSE . Change to:

setDefaultCloseOperation(DISPOSE_ON_CLOSE);

Reference: WindowConstants

    
03.11.2014 / 17:12