Modal JDialog in an applet

To create a modal JDialog, you have to pass a reference to a parent Frame or JDialog. In applets, this may be a problem, since you create no Frames. However, every Java plugin implementation known to me actually creates a Frame and puts the applet in it. So, just look it up. Add this method to your applet and use it when instantiating modal JDialogs.

  private Frame findParentFrame(){ 
    Container c = this; 
    while(c != null){ 
      if (c instanceof Frame) 
        return (Frame)c; 
      c = c.getParent(); 
    return (Frame)null; 

See also Always Set Parent For Modal Dialogs.


Comments? Corrections? Contact us or Login to edit pages directly (registration is free and takes less than displaying a JLabel)
  howto/modal_jdialog_in_applet.txt · Last modified: 2005/02/13 20:24 by (gojko)
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++