• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 15. Layout > Defining the Grid

15.7. Defining the Grid

Generally speaking, a grid layout that contains a single column or row is uncommon. Normally, the numColumns field is used to force the row of controls to wrap, thereby defining both the number of columns and rows in the layout. For example, setting numColumns to 6 in the following example causes six columns and two rows.

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 6;
    shell.setLayout(layout);
    for (int i=0; i<12; i++) {
        Button button = new Button(shell, SWT.PUSH);
        button.setText("B" + i);
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
}


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint