Java's swing. Grouplayout How to use and instance of layout manager

Source: Internet
Author: User
Tags addgroup

GroupLayoutis one LayoutManager that groups components hierarchically to determine their Container position in. It GroupLayout is primarily intended for use by generators, but can also be coded manually. The grouping Group is done by an instance of the class. GroupLayouttwo groups are supported. Serial groups (sequential group) place their child elements sequentially, one after the other. The parallel group (parallel group) is able to align its child elements in four ways.

Each group can contain any number of elements, where the element has Group , Component or gaps (GAP). A gap can be treated as an invisible component with a minimum size, a preferred size, and a maximum size. In addition, the GroupLayout preferred clearance whose value is taken is also supported LayoutStyle .

GroupLayout是一个很重要的是额布局管理器,在jdk 1.6才加入,配合其它的管理器可以实现很好的界面。

。。

GroupLayout必须要设置它的GroupLayout.setHorizontalGroup和GroupLayout.setVerticalGroup。

Grouplayout.sethorizontalgroup refers to the level of determination, the following example "account" and "password" is a level, the other components are also a level. Please see the code for details

Grouplayout.setverticalgroup. is determined by the vertical. Their level is to set the priority level of the component according to the group, and the higher the level, the higher it appears.

Grouplayout.sethorizontalgroup (Sequentialgroup (Parallelgroup (component)));

Probably is in this order to add, of course, not so simple settings, multiple component added to Parallelgroup, and then multiple Parallelgroup added to Sequentialgroup inside,

And then set it to Grouplayout.

The following example, setting Grouplayout.sethorizontalgroup, is to add 2 and 4 to a parallelgroup.addcomponent (component), the other 1, Add the 3,5,6,7,8 to another parallelgroup, and then add the two parallelgroup in order to Sequentialgroup.addgrou (Parallelgroup);

/*** @author: Tao Weiki, Weibo: http://weibo.com/taoandtao* @date: 2012/12/10* @place: China soft Software College of Guangzhou University */import Javax.swing.grouplayout;import Javax.swing.grouplayout.alignment;import Javax.swing.jbutton;import Javax.swing.jlabel;import Javax.swing.jpasswordfield;import Javax.swing.jradiobutton;import        Javax.swing.jtextfield;public class MyFrame extends Javax.swing.JFrame {public static void main (string[] args) {    MyFrame f = new MyFrame ();    } JLabel Label1;    JLabel Label2;    JLabel Label3;    JTextField TF;    JPasswordField psf;    Jradiobutton Rb1;    Jradiobutton Rb2;    JButton bt1;    JButton BT2;        Public MyFrame () {this.setvisible (true);        This.setsize (250, 220);        This.setvisible (TRUE);        This.setlocation (400, 200);        Label1 = new JLabel ("China soft BBS fast landing");        Label2 = new JLabel ("Account:");        Label3 = new JLabel ("Password:");        tf = new JTextField ();        PSF = new JPasswordField ();        RB1 = new Jradiobutton ("Remember Password"); RB2 = new JradiobutTon ("Automatic Landing");        BT1 = new JButton ("login");        Creates grouplayout grouplayout layout = new Grouplayout (This.getcontentpane ()) for the specified Container;        This.getcontentpane (). setlayout (layout);        Create a horizontal continuous group of grouplayout, with the first Parallelgroup added, the higher the priority level.        Grouplayout.sequentialgroup Hgroup = Layout.createsequentialgroup (); Hgroup.addgap (5);//Add Interval Hgroup.addgroup (Layout.createparallelgroup (). AddComponent (Label2). Addcompon        ENT (LABEL3));        Hgroup.addgap (5); Hgroup.addgroup (Layout.createparallelgroup (). AddComponent (Label1). AddComponent (PSF). AddComponent (RB1). AddC        Omponent (RB2). addcomponent (TF). AddComponent (BT1));        Hgroup.addgap (5);        Layout.sethorizontalgroup (Hgroup);        Create a vertical continuous group of grouplayout, with the first Parallelgroup added, the higher the priority level.        Grouplayout.sequentialgroup Vgroup = Layout.createsequentialgroup ();        Vgroup.addgap (10); Vgroup.addgroup (Layout.createparallelgroup (). AddComponent (Label1));        Vgroup.addgap (10);        Vgroup.addgroup (Layout.createparallelgroup (). AddComponent (Label2). AddComponent (TF));        Vgroup.addgap (5);        Vgroup.addgroup (Layout.createparallelgroup (). AddComponent (LABEL3). AddComponent (PSF));        Vgroup.addgroup (Layout.createparallelgroup (). AddComponent (RB1));        Vgroup.addgroup (Layout.createparallelgroup (). AddComponent (RB2));        Vgroup.addgroup (Layout.createparallelgroup (alignment.trailing). AddComponent (BT1));        Vgroup.addgap (10);    Set Vertical Group Layout.setverticalgroup (vgroup); }}


Http://www.cnblogs.com/taoweiji/archive/2012/12/10/2812221.html

Java's swing. Grouplayout How to use and instance of Layout Manager (GO)

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.