|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.swt.widgets.Widget org.eclipse.swt.widgets.Control org.eclipse.swt.widgets.Scrollable org.eclipse.swt.widgets.Composite org.eclipse.swt.custom.ScrolledComposite
public class ScrolledComposite
A ScrolledComposite provides scrollbars and will scroll its content when the user uses the scrollbars.
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().
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 ();
}
Field Summary |
---|
Fields inherited from class org.eclipse.swt.widgets.Control |
---|
handle |
Constructor Summary | |
---|---|
ScrolledComposite(org.eclipse.swt.widgets.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 | |
---|---|
boolean |
getAlwaysShowScrollBars()
Returns the Always Show Scrollbars flag. |
org.eclipse.swt.widgets.Control |
getContent()
Get the content that is being scrolled. |
boolean |
getExpandHorizontal()
Returns true if the content control
will be expanded to fill available horizontal space. |
boolean |
getExpandVertical()
Returns true if the content control
will be expanded to fill available vertical space. |
int |
getMinHeight()
Returns the minimum height of the content control. |
int |
getMinWidth()
Returns the minimum width of the content control. |
org.eclipse.swt.graphics.Point |
getOrigin()
Return the point in the content that currently appears in the top left corner of the scrolled composite. |
boolean |
getShowFocusedControl()
Returns true 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(org.eclipse.swt.widgets.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 |
setLayout(org.eclipse.swt.widgets.Layout layout)
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(org.eclipse.swt.graphics.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 x,
int y)
Scrolls the content so that the specified point in the content is in the top left corner. |
void |
setOrigin(org.eclipse.swt.graphics.Point origin)
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(org.eclipse.swt.widgets.Control control)
Scrolls the content of the receiver so that the control is visible. |
Methods inherited from class org.eclipse.swt.widgets.Composite |
---|
computeSize, getChildren, getLayout, getTabList, internal_getCompositeHandle, internal_isLayoutDeferred, layout, layout, setTabList |
Methods inherited from class org.eclipse.swt.widgets.Scrollable |
---|
computeTrim, getClientArea, getHorizontalBar, getVerticalBar |
Methods inherited from class org.eclipse.swt.widgets.Control |
---|
addControlListener, addFocusListener, addKeyListener, addListener, addMouseListener, addMouseMoveListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getBackground, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getParent, getShell, getSize, getStyle, getToolTipText, getVisible, internal_dispose_GC, internal_getCommandChildren, internal_isDisposed, internal_isVisible, internal_new_GC, internal_setCommandChildren, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeKeyListener, removeListener, removeMouseListener, removeMouseMoveListener, removePaintListener, removeTraverseListener, setBackground, setBounds, setBounds, setCapture, setEnabled, setFocus, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update |
Methods inherited from class org.eclipse.swt.widgets.Widget |
---|
addDisposeListener, dispose, getData, getData, getDisplay, isDisposed, notifyListeners, removeDisposeListener, setData, setData, toString |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ScrolledComposite(org.eclipse.swt.widgets.Composite parent, int style)
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 the int
"|" operator) two or more
of those SWT
style constants. The class description
lists the style constants that are applicable to the class.
Style bits are also inherited from superclasses.
parent
- a widget which will be the parent of the new instance (cannot be null)style
- the style of widget to construct
java.lang.IllegalArgumentException
- org.eclipse.swt.SWTException
- SWT.H_SCROLL
,
SWT.V_SCROLL
,
Control.getStyle()
Method Detail |
---|
public boolean getAlwaysShowScrollBars()
public boolean getExpandHorizontal()
true
if the content control
will be expanded to fill available horizontal space.
org.eclipse.swt.SWTException
- public boolean getExpandVertical()
true
if the content control
will be expanded to fill available vertical space.
org.eclipse.swt.SWTException
- public int getMinWidth()
org.eclipse.swt.SWTException
- public int getMinHeight()
org.eclipse.swt.SWTException
- public org.eclipse.swt.widgets.Control getContent()
public boolean getShowFocusedControl()
true
if the receiver automatically scrolls to a focused child control
to make it visible. Otherwise, returns false
.
org.eclipse.swt.SWTException
- public org.eclipse.swt.graphics.Point getOrigin()
org.eclipse.swt.SWTException
- public void setOrigin(org.eclipse.swt.graphics.Point origin)
origin
- the point on the content to appear in the top left corner
org.eclipse.swt.SWTException
- public void setOrigin(int x, int y)
x
- the x coordinate of the content to appear in the top left cornery
- the y coordinate of the content to appear in the top left corner
org.eclipse.swt.SWTException
- public void setAlwaysShowScrollBars(boolean show)
show
- true to show the scrollbars even when not required, false to show scrollbars only when required
org.eclipse.swt.SWTException
- public void setContent(org.eclipse.swt.widgets.Control content)
content
- the control to be displayed in the content area
org.eclipse.swt.SWTException
- public void setExpandHorizontal(boolean expand)
expand
- true to expand the content control to fill available horizontal space
org.eclipse.swt.SWTException
- public void setExpandVertical(boolean expand)
expand
- true to expand the content control to fill available vertical space
org.eclipse.swt.SWTException
- public void setLayout(org.eclipse.swt.widgets.Layout layout)
Note: No Layout can be set on this Control because it already manages the size and position of its children.
setLayout
in class org.eclipse.swt.widgets.Composite
layout
- the receiver's new layout or null
org.eclipse.swt.SWTException
- public void setMinHeight(int height)
height
- the minimum height or 0 for default height
org.eclipse.swt.SWTException
- public void setMinSize(org.eclipse.swt.graphics.Point size)
size
- the minimum size or null for the default size
org.eclipse.swt.SWTException
- public void setMinSize(int width, int height)
width
- the minimum width or 0 for default widthheight
- the minimum height or 0 for default height
org.eclipse.swt.SWTException
- public void setMinWidth(int width)
width
- the minimum width or 0 for default width
org.eclipse.swt.SWTException
- public void setShowFocusedControl(boolean show)
false
, show a focused control is off.
By default, show a focused control is off.
show
- true
to show a focused control.
org.eclipse.swt.SWTException
- public void showControl(org.eclipse.swt.widgets.Control control)
control
- the control to be shown
java.lang.IllegalArgumentException
- org.eclipse.swt.SWTException
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |