JAVA ---- example of framework Layout

Source: Internet
Author: User

[Java] view plaincopy
/*
Time:
2012-10-18
Author:
Yang Zi
Program:
Display the frame Layout
*/
Import javax. swing .*;
Import java. awt .*;
Class Day1018_BoxLayout
{
Public static void main (String [] args)
{
JFrame f = new JFrame ("window ");
Container c = f. getContentPane (); // create a horizontal box
Box h1 = Box. createHorizontalBox (); // create a vertical Box
Box v1 = Box. createVerticalBox (); // create a vertical Box
Box v2 = Box. createVerticalBox (); // create a vertical Box
Box v3 = Box. createVerticalBox (); // create a vertical Box
For (int I = 0; I <10; I ++)
{
V1.add (new JButton ("G1 "));
V1.add (Box. createVerticalStrut (10); // Add the pillar to control the spacing of 10

}
H1.add (v1); // Add the vertical box to the horizontal box
For (int j = 0; j <10; j ++)
{
V2.add (new JButton ("G2 "));
V2.add (Box. createVerticalStrut (20); // Add the pillar with a distance of 20

}
H1.add (v2); // Add the vertical box to the horizontal box
For (int k = 0; k <10; k ++)
{
V3.add (new JButton ("G3 "));
V3.add (Box. createVerticalStrut (15); // Add the pillar to control the spacing of 15
}
H1.add (v3); // Add the vertical box to the horizontal box
C. add (h1 );
F. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE );
F. setVisible (true );
F. pack ();
}
}

Related Article

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.