1
I created a frame of this genre:
But, since it was to present that the client was having trouble connecting to a server, it was better to move to Jdialog
Problem: I can’t make Jdialog visible
Code:
public class WaitingJoption extends JDialog { //se for JFrame funciona direito
public WaitingJoption() {
initUI();
}
private void initUI() {
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);
}
});
}
}
The best would be to use a Jdialog for this and avoid having multiple Jframe in your program. By the way, with Jdialog you can make the modal component, preventing the user from trying to access another functionality of the program while trying to reconnect.
– Renan Gomes
I have tried to implement this idea but I could not get it to work... There is no error but also I can not make it work, I will post code...
– jsantos1991
I tested here and launched an Exception on line 50. You are using the constant
EXIT_ON_CLOSE
(which is for Jframe components) in a Jdialog. Try switching tosetDefaultCloseOperation(DISPOSE_ON_CLOSE);
– Renan Gomes
That’s right, I don’t know why in mine you don’t make that exception, you create an answer with that so you can mark it as right
– jsantos1991