ScrolledComposite

ScrolledComposites are Composites that provide horizontal and vertical scrollbars if the contained Control does not fully fit the ScrolledComposite area on the screen. If a MIDlet provides its own ScrolledComposite implementation, the implementation is overriden with the one available on the device.

Figure: ScrolledComposite

To create a scrollable Control, first create a ScrolledComposite object to hold the Control, and then create the Control and set it as the content of the ScrolledComposite.

The following code snippet shows you how to create a ScrolledComposite with a single Button whose size is set to 200 x 200 pixels. If the ScrolledComposite area cannot fully contain the Button, scrollbars are shown as appropriate.

// Create a ScrolledComposite
ScrolledComposite sc1 = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
// Create a Button for the ScrolledComposite, fix the size at 200 x 200 pixels
Button b1 = new Button(sc1, SWT.PUSH);
b1.setSize(200, 200);
b1.setText("Button 1");
// Set the Button as the content of the ScrolledComposite
sc1.setContent(b1);

The following code snippet shows you how to create a ScrolledComposite with a single Button whose minimum size is 200 x 200 pixels. If the ScrolledComposite area cannot fully contain the Button at the minimum size, scrollbars are shown as appropriate. If the ScrolledComposite area is larger than 200 x 200 pixels, the Button is resized to fill the available area.

// Create a ScrolledComposite
ScrolledComposite sc2 = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
// Create a Button for the ScrolledComposite, do not define a size
Button b2 = new Button(sc2, SWT.PUSH);
b2.setText("Button 2");
// Set the Button as the content of the ScrolledComposite
sc2.setContent(b2);
// Set the ScrolledComposite to expand the size of its content
// if the ScrolledComposite area is larger than setMinSize
sc2.setExpandHorizontal(true);
sc2.setExpandVertical(true);
// Set the minimum width and height at which content is resized
sc2.setMinSize(200, 200);