To set the modal form and start position in swing

Source: Internet
Author: User

About Modal Forms

Only JDialog in Swing can be set to a Modal form, whose methods can be passed in a constructor (such as "JDialog (Frame owner, Boolean Modal)"), or by using the Setmodal (Boolean) method, which A method is inherited from the Dialog class.

In the JFrame class, the Modal form cannot be set through a method such as JDialog, where a friend tries to simulate a windowdeiconified form by Requestfocus () at Modal (), as follows:

public class Mymodalframe extends JFrame implements WindowListener ... {
Private JFrame frame = null;
Private Boolean modal = false;
Private String title = null;
Public mymodalframe () ... {
This (null, false);
}
Public Mymodalframe (JFrame frame) ... {
This (frame, false);
}
Public Mymodalframe (JFrame frame, Boolean modal) ... {
This (frame, modal, "");
}
Public Mymodalframe (JFrame frame, Boolean modal, String title) ... {
Super (title);
This.frame = frame;
This.modal = modal;
This.title = title;
This.init ();
}
private void init () ...      {
if (modal)
Frame.setenabled (false);
This.addwindowlistener (this);
}
public void windowopened (WindowEvent windowevent) ... {
}
public void windowclosing (WindowEvent windowevent) ...    {
if (modal)
frame.setenabled (true);
}
   public void windowclosed (WindowEvent windowevent) ... {
}
public void windowiconified (WindowEvent windowevent) ... {
}
public void windowdeiconified (WindowEvent windowevent) ... {
}
public void windowactivated (WindowEvent windowevent) ... {
}
public void windowdeactivated (WindowEvent windowevent) ...    {
if (modal)
This.requestfocus ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.