ScrolledComposite

A ScrolledComposite provides scrollbars and will scroll its content when the user uses the scrollbars.

More...

Constructors

this
this(Composite parent, int style)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. <p> The style value is either one of the style constants defined in class <code>SWT</code> which is applicable to instances of this class, or must be built by <em>bitwise OR</em>'ing together (that is, using the <code>int</code> "|" operator) two or more of those <code>SWT</code> style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses. </p>

Members

Functions

getAlwaysShowScrollBars
bool 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
Control getContent()

Get the content that is being scrolled.

getExpandHorizontal
bool getExpandHorizontal()

Returns <code>true</code> if the content control will be expanded to fill available horizontal space.

getExpandVertical
bool getExpandVertical()

Returns <code>true</code> if the content control will be expanded to fill available vertical space.

getMinHeight
int getMinHeight()

Returns the minimum height of the content control.

getMinWidth
int getMinWidth()

Returns the minimum width of the content control.

getOrigin
Point getOrigin()

Return the point in the content that currently appears in the top left corner of the scrolled composite.

getShowFocusedControl
bool getShowFocusedControl()

Returns <code>true</code> if the receiver automatically scrolls to a focused child control to make it visible. Otherwise, returns <code>false</code>.

setAlwaysShowScrollBars
void setAlwaysShowScrollBars(bool 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
void setContent(Control content)

Set the content that will be scrolled.

setExpandHorizontal
void setExpandHorizontal(bool 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
void setExpandVertical(bool 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
void setLayout(Layout layout)

Sets the layout which is associated with the receiver to be the argument which may be null. <p> Note: No Layout can be set on this Control because it already manages the size and position of its children. </p>

setMinHeight
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
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
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
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
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.

setOrigin
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.

setShowFocusedControl
void setShowFocusedControl(bool show)

Configure the receiver to automatically scroll to a focused child control to make it visible.

showControl
void showControl(Control control)

Scrolls the content of the receiver so that the control is visible.

Inherited Members

From Composite

changed
void changed(Control[] changed)

Clears any data that has been cached by a Layout for all widgets that are in the parent hierarchy of the changed control up to and including the receiver. If an ancestor does not have a layout, it is skipped.

getBackgroundMode
int getBackgroundMode()

Returns the receiver's background drawing mode. This will be one of the following constants defined in class <code>SWT</code>: <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>, <code>INHERTIT_FORCE</code>.

getChildren
Control[] getChildren()

Returns a (possibly empty) array containing the receiver's children. Children are returned in the order that they are drawn. The topmost control appears at the beginning of the array. Subsequent controls draw beneath this control and appear later in the array. <p> Note: This is not the actual structure used by the receiver to maintain its list of children, so modifying the array will not affect the receiver. </p>

getLayout
Layout getLayout()

Returns layout which is associated with the receiver, or null if one has not been set.

getLayoutDeferred
bool getLayoutDeferred()

Returns <code>true</code> if the receiver has deferred the performing of layout, and <code>false</code> otherwise.

getTabList
Control[] getTabList()

Gets the (possibly empty) tabbing order for the control.

isLayoutDeferred
bool isLayoutDeferred()

Returns <code>true</code> if the receiver or any ancestor up to and including the receiver's nearest ancestor shell has deferred the performing of layouts. Otherwise, <code>false</code> is returned.

layout
void layout()

If the receiver has a layout, asks the layout to <em>lay out</em> (that is, set the size and location of) the receiver's children. If the receiver does not have a layout, do nothing. <p> This is equivalent to calling <code>layout(true)</code>. </p> <p> Note: Layout is different from painting. If a child is moved or resized such that an area in the parent is exposed, then the parent will paint. If no child is affected, the parent will not paint. </p>

layout
void layout(bool changed)

If the receiver has a layout, asks the layout to <em>lay out</em> (that is, set the size and location of) the receiver's children. If the argument is <code>true</code> the layout must not rely on any information it has cached about the immediate children. If it is <code>false</code> the layout may (potentially) optimize the work it is doing by assuming that none of the receiver's children has changed state since the last layout. If the receiver does not have a layout, do nothing. <p> If a child is resized as a result of a call to layout, the resize event will invoke the layout of the child. The layout will cascade down through all child widgets in the receiver's widget tree until a child is encountered that does not resize. Note that a layout due to a resize will not flush any cached information (same as <code>layout(false)</code>). </p> <p> Note: Layout is different from painting. If a child is moved or resized such that an area in the parent is exposed, then the parent will paint. If no child is affected, the parent will not paint. </p>

layout
void layout(bool changed, bool all)

If the receiver has a layout, asks the layout to <em>lay out</em> (that is, set the size and location of) the receiver's children. If the changed argument is <code>true</code> the layout must not rely on any information it has cached about its children. If it is <code>false</code> the layout may (potentially) optimize the work it is doing by assuming that none of the receiver's children has changed state since the last layout. If the all argument is <code>true</code> the layout will cascade down through all child widgets in the receiver's widget tree, regardless of whether the child has changed size. The changed argument is applied to all layouts. If the all argument is <code>false</code>, the layout will <em>not</em> cascade down through all child widgets in the receiver's widget tree. However, if a child is resized as a result of a call to layout, the resize event will invoke the layout of the child. Note that a layout due to a resize will not flush any cached information (same as <code>layout(false)</code>). </p> <p> Note: Layout is different from painting. If a child is moved or resized such that an area in the parent is exposed, then the parent will paint. If no child is affected, the parent will not paint. </p>

layout
void layout(Control[] changed)

Forces a lay out (that is, sets the size and location) of all widgets that are in the parent hierarchy of the changed control up to and including the receiver. The layouts in the hierarchy must not rely on any information cached about the changed control or any of its ancestors. The layout may (potentially) optimize the work it is doing by assuming that none of the peers of the changed control have changed state since the last layout. If an ancestor does not have a layout, skip it. <p> Note: Layout is different from painting. If a child is moved or resized such that an area in the parent is exposed, then the parent will paint. If no child is affected, the parent will not paint. </p>

setBackgroundMode
void setBackgroundMode(int mode)

Sets the background drawing mode to the argument which should be one of the following constants defined in class <code>SWT</code>: <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>, <code>INHERIT_FORCE</code>.

setLayout
void setLayout(Layout layout)

Sets the layout which is associated with the receiver to be the argument which may be null.

setLayoutDeferred
void setLayoutDeferred(bool defer)

If the argument is <code>true</code>, causes subsequent layout operations in the receiver or any of its children to be ignored. No layout of any kind can occur in the receiver or any of its children until the flag is set to false. Layout operations that occurred while the flag was <code>true</code> are remembered and when the flag is set to <code>false</code>, the layout operations are performed in an optimized manner. Nested calls to this method are stacked.

setTabList
void setTabList(Control[] tabList)

Sets the tabbing order for the specified controls to match the order that they occur in the argument list.

Detailed Description

<p>There are two ways to use the ScrolledComposite:

<p> 1) Set the size of the control that is being scrolled and the ScrolledComposite will show scrollbars when the contained control can not be fully seen.

2) The second way imitates the way a browser would work. Set the minimum size of the control and the ScrolledComposite will show scroll bars if the visible area is less than the minimum size of the control and it will expand the size of the control if the visible area is greater than the minimum size. This requires invoking both setMinWidth(), setMinHeight() and setExpandHorizontal(), setExpandVertical().

<code><pre> 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 (); } </pre></code>

<dl> <dt><b>Styles:</b><dd>H_SCROLL, V_SCROLL </dl>

@see <a href="http://www.eclipse.org/swt/snippets/#scrolledcomposite">ScrolledComposite snippets</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>

Meta