Click to See Complete Forum and Search --> : How to display a modal dialog from a servlet


Stefan
May 4th, 2000, 07:53 AM
Hi!

I'm trying to display a modal dialog from a servlet (in it's init code it's supposed to ask the guy on the web server a question, I DO know that the window will be displayed on that end (as opposed to in the browser on the other end).
Well... before I try that I want to display a dialog from a main function but I seem to be having problems with that. This dialog should be modal so I can't use a frame (or can I?).
So I need to know how to how to display a modal dialog with no parent frame (just straight from the main function... or servlet).

Here's what happens when I try this. My dialog always gets lost... I can't see it! I construct it with true in the modal boolean and... nada!

Here's some code:
The main method:

//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
}
CipherKeyDlg d = new CipherKeyDlg(null, "Enter Cipher Key", true);
System.out.println("hello");
}



The CipherKeyDlg class:

public class CipherKeyDlg extends JDialog {
JLabel lblPrompt = new JLabel();
JTextField txtCipherKey = new JTextField();
JButton btnOK = new JButton();

public CipherKeyDlg(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}

public CipherKeyDlg()
{
this(null, "", true);
}

//Component initialization
private void jbInit() throws Exception
{
//Center the dialog
this.validate();
this.setSize(new Dimension(340, 220));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;

lblPrompt.setText("Enter Komodo Cipher Key:");
lblPrompt.setBounds(new Rectangle(100, 100, 150, 21));
this.getContentPane().setLayout(null);
this.setResizable(false);
this.setTitle("Enter Cipher Key");
this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
txtCipherKey.setToolTipText("Enter Komodo Cipher Key");
txtCipherKey.setBounds(new Rectangle(110, 125, 200, 21));
btnOK.setSelected(true);
btnOK.setText("OK");
btnOK.setBounds(new Rectangle(250, 160, 79, 27));
btnOK.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnOK_actionPerformed(e);
}
});
this.getContentPane().add(lblPrompt, null);
this.getContentPane().add(txtCipherKey, null);
this.getContentPane().add(btnOK, null);
}
}




The jbInit code works for a frame... but not for a Dialog???

Any ideas?

Thanks in advance,
Stefan

================================================
Did you know that in the new IP protocol (IPv6) there are enough IP addresses to give each protone on earth an IP address!
That's just about 3.7 million billion IP addresses per each square meter on the face of the earth. That's a lot of IP!