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

Chapter 15. Layout > Forcing Controls to Wrap

15.12. Forcing Controls to Wrap

Consider the following example that uses GridLayout to create a very simple dialog with a label, a list, and two buttons.

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    Label label = new Label(shell, SWT.WRAP);
    GridData labelData = new GridData();
    labelData.horizontalSpan = 2;
    labelData.horizontalAlignment = SWT.FILL;
    label.setLayoutData(labelData);
    label.setText(
        "This is lots of really nice text that " +
        "should wrap but does not. Is this a bug?");
    int style = SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL;
    List list = new List(shell, style);
    list.setItems(new String[] {"A", "B", "C", "D"});
    GridData listData =
        new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    list.setLayoutData(listData);
    Button okButton = new Button(shell, SWT.PUSH);
    okButton.setText("Ok");
    Button cancelButton = new Button(shell, SWT.PUSH);
    cancelButton.setText("Cancel");
    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