There are two ways to use the ScrolledComposite:
public static void main (String [] args) {
Display display = new Display ();
Color red = display.getSystemColor(SWT.COLOR_RED);
Color blue = display.getSystemColor(SWT.COLOR_BLUE);
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
// set the size of the scrolled content - method 1
final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
final Composite c1 = new Composite(sc1, SWT.NONE);
sc1.setContent(c1);
c1.setBackground(red);
GridLayout layout = new GridLayout();
layout.numColumns = 4;
c1.setLayout(layout);
Button b1 = new Button (c1, SWT.PUSH);
b1.setText("first button");
c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
// set the minimum width and height of the scrolled content - method 2
final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
sc2.setExpandHorizontal(true);
sc2.setExpandVertical(true);
final Composite c2 = new Composite(sc2, SWT.NONE);
sc2.setContent(c2);
c2.setBackground(blue);
layout = new GridLayout();
layout.numColumns = 4;
c2.setLayout(layout);
Button b2 = new Button (c2, SWT.PUSH);
b2.setText("first button");
sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Button add = new Button (shell, SWT.PUSH);
add.setText("add children");
final int[] index = new int[]{0};
add.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
index[0]++;
Button button = new Button(c1, SWT.PUSH);
button.setText("button "+index[0]);
// reset size of content so children can be seen - method 1
c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
c1.layout();
button = new Button(c2, SWT.PUSH);
button.setText("button "+index[0]);
// reset the minimum width and height so children can be seen - method 2
sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
c2.layout();
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
| Modifier and Type | Field and Description |
|---|---|
| pack-priv boolean | |
| pack-priv Control | |
| pack-priv Listener | |
| pack-priv boolean | |
| pack-priv boolean | |
| pack-priv Listener | |
| pack-priv int | |
| pack-priv int | |
| pack-priv boolean | |
| pack-priv boolean |
| Access | Constructor and Description |
|---|---|
| public | ScrolledComposite(Composite
a widget which will be the parent of the new instance (cannot be null) parent, int the style of widget to construct style)Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static int | |
| pack-priv boolean | |
| public boolean | Returns: the Always Show Scrollbars flag valueReturns the Always Show Scrollbars flag. |
| public Control | Returns: the control displayed in the content areaGet the content that is being scrolled. |
| public boolean | Returns: the receiver's horizontal expansion stateReturns |
| public boolean | Returns: the receiver's vertical expansion stateReturns |
| public int | |
| public int | |
| public Point | Returns: the point in the content that currently appears in the top left corner of the scrolled composite. If no content has been set, this returns (0, 0).Return the point in the content that currently appears in the top left corner of the scrolled composite. |
| public boolean | Returns: a boolean indicating whether focused child controls are automatically scrolled into the viewportReturns |
| pack-priv void | |
| pack-priv boolean | |
| pack-priv boolean | |
| public void | setAlwaysShowScrollBars(boolean
true to show the scrollbars even when not required, false to show scrollbars only when required show)Set the Always Show Scrollbars flag. |
| public void | setContent(Control
the control to be displayed in the content area content)Set the content that will be scrolled. |
| public void | setExpandHorizontal(boolean
true to expand the content control to fill available horizontal space expand)Configure the ScrolledComposite to resize the content object to be as wide as the ScrolledComposite when the width of the ScrolledComposite is greater than the minimum width specified in setMinWidth. |
| public void | setExpandVertical(boolean
true to expand the content control to fill available vertical space expand)Configure the ScrolledComposite to resize the content object to be as tall as the ScrolledComposite when the height of the ScrolledComposite is greater than the minimum height specified in setMinHeight. |
| public void | setLayout(Layout
the receiver's new layout or null layout)Overrides org. |
| public void | setMinHeight(int
the minimum height or 0 for default height height)Specify the minimum height at which the ScrolledComposite will begin scrolling the content with the vertical scroll bar. |
| public void | setMinSize(Point
the minimum size or null for the default size size)Specify the minimum width and height at which the ScrolledComposite will begin scrolling the content with the horizontal scroll bar. |
| public void | setMinSize(int
the minimum width or 0 for default width width, int the minimum height or 0 for default height height)Specify the minimum width and height at which the ScrolledComposite will begin scrolling the content with the horizontal scroll bar. |
| public void | setMinWidth(int
the minimum width or 0 for default width width)Specify the minimum width at which the ScrolledComposite will begin scrolling the content with the horizontal scroll bar. |
| public void | |
| public void | setOrigin(int
the x coordinate of the content to appear in the top left corner x, int the y coordinate of the content to appear in the top left corner y)Scrolls the content so that the specified point in the content is in the top left corner. |
| public void | setShowFocusedControl(boolean
true to show a focused control.Configure the receiver to automatically scroll to a focused child control to make it visible. |
| public void | showControl(Control
the control to be shown control)Scrolls the content of the receiver so that the control is visible. |
| pack-priv void |
| alwaysShowScroll | back to summary |
|---|---|
| pack-priv boolean alwaysShowScroll | |
| content | back to summary |
|---|---|
| pack-priv Control content | |
| contentListener | back to summary |
|---|---|
| pack-priv Listener contentListener | |
| expandHorizontal | back to summary |
|---|---|
| pack-priv boolean expandHorizontal | |
| expandVertical | back to summary |
|---|---|
| pack-priv boolean expandVertical | |
| filter | back to summary |
|---|---|
| pack-priv Listener filter | |
| minHeight | back to summary |
|---|---|
| pack-priv int minHeight | |
| minWidth | back to summary |
|---|---|
| pack-priv int minWidth | |
| showFocusedControl | back to summary |
|---|---|
| pack-priv boolean showFocusedControl | |
| showNextFocusedControl | back to summary |
|---|---|
| pack-priv boolean showNextFocusedControl | |
| ScrolledComposite | back to summary |
|---|---|
| public ScrolledComposite(Composite parent, int style) Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
The style value is either one of the style constants defined in
class
| |
| checkStyle | back to summary |
|---|---|
| pack-priv static int checkStyle(int style) | |
| contains | back to summary |
|---|---|
| pack-priv boolean contains(Control control) | |
| getAlwaysShowScrollBars | back to summary |
|---|---|
| public boolean getAlwaysShowScrollBars() Returns the Always Show Scrollbars flag. True if the scrollbars are always shown even if they are not required. False if the scrollbars are only visible when some part of the composite needs to be scrolled to be seen. The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the horizontal and vertical directions.
| |
| getContent | back to summary |
|---|---|
| public Control getContent() Get the content that is being scrolled.
| |
| getExpandHorizontal | back to summary |
|---|---|
| public boolean getExpandHorizontal() Returns
| |
| getExpandVertical | back to summary |
|---|---|
| public boolean getExpandVertical() Returns
| |
| getMinHeight | back to summary |
|---|---|
| public int getMinHeight() Returns the minimum height of the content control.
| |
| getMinWidth | back to summary |
|---|---|
| public int getMinWidth() Returns the minimum width of the content control.
| |
| getOrigin | back to summary |
|---|---|
| public Point getOrigin() Return the point in the content that currently appears in the top left corner of the scrolled composite.
| |
| getShowFocusedControl | back to summary |
|---|---|
| public boolean getShowFocusedControl() Returns
| |
| hScroll | back to summary |
|---|---|
| pack-priv void hScroll() | |
| needHScroll | back to summary |
|---|---|
| pack-priv boolean needHScroll(Rectangle contentRect, boolean vVisible) | |
| needVScroll | back to summary |
|---|---|
| pack-priv boolean needVScroll(Rectangle contentRect, boolean hVisible) | |
| setAlwaysShowScrollBars | back to summary |
|---|---|
| public void setAlwaysShowScrollBars(boolean show) Set the Always Show Scrollbars flag. True if the scrollbars are always shown even if they are not required. False if the scrollbars are only visible when some part of the composite needs to be scrolled to be seen. The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the horizontal and vertical directions.
| |
| setContent | back to summary |
|---|---|
| public void setContent(Control content) Set the content that will be scrolled.
| |
| setExpandHorizontal | back to summary |
|---|---|
| public void setExpandHorizontal(boolean expand) Configure the ScrolledComposite to resize the content object to be as wide as the ScrolledComposite when the width of the ScrolledComposite is greater than the minimum width specified in setMinWidth. If the ScrolledComposite is less than the minimum width, the content will not be resized and instead the horizontal scroll bar will be used to view the entire width. If expand is false, this behaviour is turned off. By default, this behaviour is turned off.
| |
| setExpandVertical | back to summary |
|---|---|
| public void setExpandVertical(boolean expand) Configure the ScrolledComposite to resize the content object to be as tall as the ScrolledComposite when the height of the ScrolledComposite is greater than the minimum height specified in setMinHeight. If the ScrolledComposite is less than the minimum height, the content will not be resized and instead the vertical scroll bar will be used to view the entire height. If expand is false, this behaviour is turned off. By default, this behaviour is turned off.
| |
| setLayout | back to summary |
|---|---|
| public void setLayout(Layout layout) Overrides org. Sets the layout which is associated with the receiver to be the argument which may be null. Note No Layout can be set on this Control because it already manages the size and position of its children.
| |
| setMinHeight | back to summary |
|---|---|
| public void setMinHeight(int height) Specify the minimum height at which the ScrolledComposite will begin scrolling the content with the vertical scroll bar. This value is only relevant if setExpandVertical(true) has been set.
| |
| setMinSize | back to summary |
|---|---|
| public void setMinSize(Point size) Specify the minimum width and height at which the ScrolledComposite will begin scrolling the content with the horizontal scroll bar. This value is only relevant if setExpandHorizontal(true) and setExpandVertical(true) have been set.
| |
| setMinSize | back to summary |
|---|---|
| public void setMinSize(int width, int height) Specify the minimum width and height at which the ScrolledComposite will begin scrolling the content with the horizontal scroll bar. This value is only relevant if setExpandHorizontal(true) and setExpandVertical(true) have been set.
| |
| setMinWidth | back to summary |
|---|---|
| public void setMinWidth(int width) Specify the minimum width at which the ScrolledComposite will begin scrolling the content with the horizontal scroll bar. This value is only relevant if setExpandHorizontal(true) has been set.
| |
| setOrigin | back to summary |
|---|---|
| public void setOrigin(Point origin) Scrolls the content so that the specified point in the content is in the top left corner. If no content has been set, nothing will occur. Negative values will be ignored. Values greater than the maximum scroll distance will result in scrolling to the end of the scrollbar.
| |
| setOrigin | back to summary |
|---|---|
| public void setOrigin(int x, int y) Scrolls the content so that the specified point in the content is in the top left corner. If no content has been set, nothing will occur. Negative values will be ignored. Values greater than the maximum scroll distance will result in scrolling to the end of the scrollbar.
| |
| setShowFocusedControl | back to summary |
|---|---|
| public void setShowFocusedControl(boolean show) Configure the receiver to automatically scroll to a focused child control
to make it visible.
If show is
| |
| showControl | back to summary |
|---|---|
| public void showControl(Control control) Scrolls the content of the receiver so that the control is visible.
| |
| vScroll | back to summary |
|---|---|
| pack-priv void vScroll() | |