Pack () in SWT ()

Source: Internet
Author: User

First:
Causes this window to be sized to fit
Preferred size and layouts of its subcomponents. If
Window and/or its owner are not yet displayable, both
Are Made displayable before calculating the preferred
Size. The window will be validated after
Preferredsize is calculated.
This is the definition of Pack () in Java API. I don't know where your instructions are obtained.

From the above description, we can understand that pack () is used to automatically adjust the size of a window object. The goal of the adjustment is to make it suitable for him and all its components.
(Of course, this range must be calculated first. If the size of some space cannot be calculated, this method is invalid. However, if it cannot be calculated,
So how to display it ?)

The following is a simple example of using pack (). You can refer to the following. If the Pack () method is used and the Controller size and range of the window are used, for example, setsize will be blocked.

Import java. AWT. gridlayout;

Import javax. Swing. jbutton;
Import javax. Swing. jdialog;
Import javax. Swing. jlist;
Import javax. Swing. jpanel;
Import javax. Swing. jscrollpane;
Import javax. Swing. scrollpanelayout;

/**
* Try to use the method "pack ()"
* @ Author liym
*/
Public class jdialogtest extends jdialog {

/* Component */
Private jbutton = NULL;

/**
* Construct Method
* @ Author liym
*/
Public jdialogtest (){
// Initial Method
Init ();
// Try to use the method
This. Pack ();
}

/**
* Initial Method
* @ Return <code> void <code>
*/
Private void Init (){
// Set the size of the dialog
This. setsize (200,400 );
// Set the layout of the dialog
This. getcontentpane (). setlayout (New gridlayout ());
// The component in the dialog
Jbutton = new jbutton ("button ");
This. getcontentpane (). Add (jbutton );
}

/**
* Main method.
*
* @ Param ARGs string [] inputed strings
* @ Return <code> void </code>
*/
Public static void main (string [] ARGs ){
Jdialogtest = new jdialogtest ();
Jdialogtest. setvisible (true );
}

}

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.