• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with JDialog  RSS feed

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I'm retrieving info from a database that lasts about 7-10 seconds.
I have the following class that displays info about retrieval

class InfoDialog extends JDialog{

JLabel InfoLabel;

InfoDialog(JFrame parent, String title){

super(parent, title);
setSize(300, 70);
setLayout(new FlowLayout(FlowLayout.LEFT, 20 , 20));
setLocationRelativeTo(null);
InfoLabel = new JLabel("Retrieving database info......................");
getContentPane().add(InfoLabel);
validate();

}
}

and my retrieve method getClientinfo();
That's what I do
try{
InfoDialog infdlg = new InfoDialog(this, "Connect info");
infdlg.setModal(true);
infdlg.setVisible(true);
getClientInfo();
infdlg.setModal(false);
infdlg.setVisible(false);
infdlg.dispose();
}catch(Exception e){

JOptionPane.showMessageDialog(null, "Error : " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
The problem here is that the dialog is displayed and set to modal but it remains modal, it does not dissappear.
Could you please help?
Waiting for reply............
Thank you!
Fedai
 
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks okay to me. But I would remove this:



... because you are disposing of it on the next line.
 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I removed this
The code looks like this

InfoDialog infdlg = new InfoDialog(this, "Connect info");
infdlg.setModal(true);
infdlg.setVisible(true);
getClientInfo();
infdlg.dispose();

Doesnt work!
The dialog displays but the label does not.
When I specify setModal(true); in the constructor it displays and so
does the label but it's not removed from the screen whatever I do

infdlg.setModal(false);
infdlg.setVisible(false);
infdlg.dispose();
or simply dispose();

You know the idea, maybe you can suggest me smth different.
PLEASE HELP!
Waiting for reply.......
Thank you!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!