Class ScrolledComposite
There are two ways to use the ScrolledComposite:
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().
- Styles:
- H_SCROLL, V_SCROLL
- Since:
- 1.0
-
Constructor Summary
ConstructorDescriptionScrolledComposite
(Composite parent, int style) Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Disposes of the operating system resources associated with the receiver and all its descendents.<T> T
getAdapter
(Class<T> adapter) Implementation of theAdaptable
interface.boolean
Returns the Always Show Scrollbars flag.Get the content that is being scrolled.boolean
Returnstrue
if the content control will be expanded to fill available horizontal space.boolean
Returnstrue
if the content control will be expanded to fill available vertical space.int
Returns the minimum height of the content control.int
Returns the minimum width of the content control.Return the point in the content that currently appears in the top left corner of the scrolled composite.boolean
Returnstrue
if the receiver automatically scrolls to a focused child control to make it visible.void
setAlwaysShowScrollBars
(boolean show) Set the Always Show Scrollbars flag.void
setContent
(Control content) Set the content that will be scrolled.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.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.void
Sets the layout which is associated with the receiver to be the argument which may be null.void
setMinHeight
(int height) Specify the minimum height at which the ScrolledComposite will begin scrolling the content with the vertical scroll bar.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.void
setMinSize
(Point size) Specify the minimum width and height at which the ScrolledComposite will begin scrolling the content with the horizontal scroll bar.void
setMinWidth
(int width) Specify the minimum width at which the ScrolledComposite will begin scrolling the content with the horizontal scroll bar.void
setOrigin
(int left, int top) Scrolls the content so that the specified point in the content is in the top left corner.void
Scrolls the content so that the specified point in the content is in the top left corner.void
setShowFocusedControl
(boolean show) Configure the receiver to automatically scroll to a focused child control to make it visible.void
showControl
(Control control) Scrolls the content of the receiver so that the control is visible.Methods inherited from class org.eclipse.swt.widgets.Composite
changed, computeSize, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayoutDeferred, setTabList
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addTouchListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getShell, getSize, getToolTipText, getTouchEnabled, getVisible, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCursor, setData, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setSize, setSize, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, update
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkSubclass, checkWidget, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, toString
-
Constructor Details
-
ScrolledComposite
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
SWT
which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using theint
"|" operator) two or more of thoseSWT
style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent
- a widget which will be the parent of the new instance (cannot be null)style
- the style of widget to construct- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- See Also:
-
-
Method Details
-
setLayout
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.
- Overrides:
setLayout
in classComposite
- Parameters:
layout
- the receiver's new layout or null- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setOrigin
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.- Parameters:
origin
- the point on the content to appear in the top left corner- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- ERROR_INVALID_ARGUMENT - value of origin is outside of content
-
setOrigin
public void setOrigin(int left, int top) 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.- Parameters:
left
- the x coordinate of the content to appear in the top left cornertop
- the y coordinate of the content to appear in the top left corner- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getOrigin
Return the point in the content that currently appears in the top left corner of the scrolled composite.- 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).
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setAlwaysShowScrollBars
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.- Parameters:
show
- true to show the scrollbars even when not required, false to show scrollbars only when required- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getAlwaysShowScrollBars
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.- Returns:
- the Always Show Scrollbars flag value
-
getExpandHorizontal
public boolean getExpandHorizontal()Returnstrue
if the content control will be expanded to fill available horizontal space.- Returns:
- the receiver's horizontal expansion state
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getExpandVertical
public boolean getExpandVertical()Returnstrue
if the content control will be expanded to fill available vertical space.- Returns:
- the receiver's vertical expansion state
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setExpandHorizontal
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.- Parameters:
expand
- true to expand the content control to fill available horizontal space- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setExpandVertical
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.- Parameters:
expand
- true to expand the content control to fill available vertical space- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setMinWidth
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.- Parameters:
width
- the minimum width or 0 for default width- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getMinWidth
public int getMinWidth()Returns the minimum width of the content control.- Returns:
- the minimum width
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setMinHeight
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.- Parameters:
height
- the minimum height or 0 for default height- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getMinHeight
public int getMinHeight()Returns the minimum height of the content control.- Returns:
- the minimum height
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setMinSize
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.- Parameters:
size
- the minimum size or null for the default size- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setMinSize
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.- Parameters:
width
- the minimum width or 0 for default widthheight
- the minimum height or 0 for default height- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setContent
Set the content that will be scrolled.- Parameters:
content
- the control to be displayed in the content area- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getContent
Get the content that is being scrolled.- Returns:
- the control displayed in the content area
-
setShowFocusedControl
public void setShowFocusedControl(boolean show) Configure the receiver to automatically scroll to a focused child control to make it visible. If show isfalse
, show a focused control is off. By default, show a focused control is off.- Parameters:
show
-true
to show a focused control.- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
getShowFocusedControl
public boolean getShowFocusedControl()Returnstrue
if the receiver automatically scrolls to a focused child control to make it visible. Otherwise, returnsfalse
.- Returns:
- a boolean indicating whether focused child controls are automatically scrolled into the viewport
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
showControl
Scrolls the content of the receiver so that the control is visible.- Parameters:
control
- the control to be shown- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the control is null
- ERROR_INVALID_ARGUMENT - if the control has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
dispose
public void dispose()Description copied from class:Widget
Disposes of the operating system resources associated with the receiver and all its descendents. After this method has been invoked, the receiver and all descendents will answertrue
when sent the messageisDisposed()
. Any internal connections between the widgets in the tree will have been removed to facilitate garbage collection.NOTE: This method is not called recursively on the descendents of the receiver. This means that, widget implementers can not detect when a widget is being disposed of by re-implementing this method, but should instead listen for the
Dispose
event. -
getAdapter
Description copied from class:Widget
Implementation of theAdaptable
interface.IMPORTANT: This method is not part of the RWT public API. It is marked public only so that it can be shared within the packages provided by RWT. It should never be accessed from application code.
- Specified by:
getAdapter
in interfaceAdaptable
- Overrides:
getAdapter
in classComposite
- Parameters:
adapter
- the lookup class- Returns:
- an object that can be cast to the given class or
null
if there is no adapter associated with the given class.
-