SWT: grid layout

Source: Internet
Author: User

Public static void showgridlayout (shell ){
Gridlayout = new gridlayout ();
// Set the number of grid Columns
Gridlayout. numcolumns = 3;
// Set the mesh width.
Gridlayout. makecolumnsequalwidth = true;
// Set the whitelist and interval
Gridlayout. verticalspacing = 10; // vertical interval
Gridlayout. horizontalspacing = 10; // horizontal interval

Shell. setlayout (gridlayout );
New button (shell, SWT. Push). settext ("B1 ");
New button (shell, SWT. Push). settext ("wide button 2 ");
New button (shell, SWT. Push). settext ("button 3 ");
New button (shell, SWT. Push). settext ("B4 ");
New button (shell, SWT. Push). settext ("button 5 ");
New button (shell, SWT. Push). settext ("B6 ");

// use the griddata object
// method 1
button button1 = new button (shell, SWT. push);
button1.settext ("button");
griddata = new griddata (); // create a griddata object
griddata. horizontalalignment = griddata. fill; // set the horizontal filling mode to full cells
griddata. grabexcesshorizontalspace = true; // sets the horizontal preemption mode
// sets the cell alignment mode
// sets the horizontal alignment
griddata. horizontalalignment = SWT. beginning | SWT. left; // left alignment. The default value is SWT. beginning
// SWT. center: center horizontally
// SWT. end; or SWT. right: Right
// SWT. fill horizontally fills the entire cell

// The default vertical alignment mode is SWT. center
griddata. verticalalignment = SWT. center;
// SWT. beginning or SWT. top alignment
// SWT. center vertical center
// SWT. end or SWT. bottom alignment of bottom
// SWT. fill vertically fills the entire cell

// set the indent size
griddata. horizontalindent = 20; // set the horizontal indent to 20 pixels
griddata. verticalindent = 20; // set the vertical indent pixel size
// set the cell cross-row and cross-Column Display
griddata. horizontalspan = 2; // set to horizontally span two cells
griddata. horizontalalignment = SWT. fill;
griddata. verticalspan = 2; // set to vertically span two cells
griddata. verticalalignment = SWT. fill;
// sets the preemption mode for the cell space.
griddata. grabexcessverticalspace = true; // sets the vertical preemption
griddata. grabexcesshorizontalspace = true; // set horizontal preemption
// set the control size
// This attribute takes effect only when grabexcessverticalspace grabexcesshorizontalspace is true
griddata. minimumheight = 100; // small height
griddata. minimumwidth = 100; // minimum width
button1.setlayoutdata (griddata);

// Set the control size to change as the window changes, but only takes effect at the beginning.
Griddata. widthhint = 100; // set the width.
Griddata. heighthint = 100; // set the height.

// Use the griddata object
// Method 2
Button button2 = new button (shell, SWT. Push );
Button2.settext ("button ");
Button2.setlayoutdata (New griddata (griddata. horizontal_align_fill
| Griddata. grab_horizontal); // create with a constant, same as method 1
Button2.setlayoutdata (griddata); // sets the layout data of the button.

Shell. open ();
}

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.