|
|||||||||
| Home >> All >> org >> eclipse >> swt >> [ custom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.eclipse.swt.custom
Class ScrolledComposite

java.lang.Objectorg.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.swt.custom.ScrolledComposite
- All Implemented Interfaces:
- org.eclipse.swt.graphics.Drawable
- public class ScrolledComposite
- extends org.eclipse.swt.widgets.Composite
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 ();
}
- Styles:
- H_SCROLL, V_SCROLL
| Field Summary | |
private boolean |
alwaysShowScroll
|
private org.eclipse.swt.widgets.Control |
content
|
private org.eclipse.swt.widgets.Listener |
contentListener
|
private boolean |
expandHorizontal
|
private boolean |
expandVertical
|
private boolean |
inResize
|
private int |
minHeight
|
private int |
minWidth
|
| Fields inherited from class org.eclipse.swt.widgets.Composite |
embeddedHandle |
| Fields inherited from class org.eclipse.swt.widgets.Scrollable |
|
| Fields inherited from class org.eclipse.swt.widgets.Control |
|
| Fields inherited from class org.eclipse.swt.widgets.Widget |
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 | |
private static int |
checkStyle(int style)
|
org.eclipse.swt.graphics.Point |
computeSize(int wHint,
int hHint,
boolean changed)
Returns the preferred size of the receiver. |
boolean |
getAlwaysShowScrollBars()
Returns the Always Show Scrollbars flag. |
org.eclipse.swt.widgets.Control |
getContent()
Get the content that is being scrolled. |
org.eclipse.swt.graphics.Point |
getOrigin()
Return the point in the content that currenly appears in the top left corner of the scrolled composite. |
(package private) void |
hScroll()
|
void |
layout(boolean changed)
If the receiver has a layout, asks the layout to lay out (that is, set the size and location of) the receiver's children. |
private boolean |
needHScroll(org.eclipse.swt.graphics.Rectangle contentRect,
boolean vVisible)
|
private boolean |
needVScroll(org.eclipse.swt.graphics.Rectangle contentRect,
boolean hVisible)
|
(package private) void |
resize()
|
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. |
(package private) void |
vScroll()
|
| Methods inherited from class org.eclipse.swt.widgets.Composite |
checkSubclass, getChildren, getLayout, getTabList, layout, setFocus, setTabList |
| Methods inherited from class org.eclipse.swt.widgets.Scrollable |
computeTrim, getBorderWidth, getClientArea, getHorizontalBar, getVerticalBar |
| Methods inherited from class org.eclipse.swt.widgets.Widget |
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
content
private org.eclipse.swt.widgets.Control content
contentListener
private org.eclipse.swt.widgets.Listener contentListener
minHeight
private int minHeight
minWidth
private int minWidth
expandHorizontal
private boolean expandHorizontal
expandVertical
private boolean expandVertical
alwaysShowScroll
private boolean alwaysShowScroll
inResize
private boolean inResize
| Constructor Detail |
ScrolledComposite
public 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.
The style value is either one of the style constants defined in class
SWTwhich 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 thoseSWTstyle constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.
| Method Detail |
checkStyle
private static int checkStyle(int style)
computeSize
public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed)
- Description copied from class:
org.eclipse.swt.widgets.Control - Returns the preferred size of the receiver.
The preferred size of a control is the size that it would best be displayed at. The width hint and height hint arguments allow the caller to ask a control questions such as "Given a particular width, how high does the control need to be to show all of the contents?" To indicate that the caller does not wish to constrain a particular dimension, the constant
SWT.DEFAULTis passed for the hint.If the changed flag is
true, it indicates that the receiver's contents have changed, therefore any caches that a layout manager containing the control may have been keeping need to be flushed. When the control is resized, the changed flag will befalse, so layout manager caches can be retained.
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.
getContent
public org.eclipse.swt.widgets.Control getContent()
- Get the content that is being scrolled.
hScroll
void hScroll()
layout
public void layout(boolean changed)
- Description copied from class:
org.eclipse.swt.widgets.Composite - If the receiver has a layout, asks the layout to lay out
(that is, set the size and location of) the receiver's children.
If the the argument is
truethe layout must not rely on any cached information it is keeping about the children. If it isfalsethe layout may (potentially) simplify the work it is doing by assuming that the state of the none of the receiver's children has changed since the last layout. If the receiver does not have a layout, do nothing.
needHScroll
private boolean needHScroll(org.eclipse.swt.graphics.Rectangle contentRect, boolean vVisible)
needVScroll
private boolean needVScroll(org.eclipse.swt.graphics.Rectangle contentRect, boolean hVisible)
resize
void resize()
getOrigin
public org.eclipse.swt.graphics.Point getOrigin()
- Return the point in the content that currenly appears in the top left
corner of the scrolled composite.
- Since:
- 2.0
setOrigin
public 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. 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.
- Since:
- 2.0
setOrigin
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.
- Since:
- 2.0
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.
setContent
public void setContent(org.eclipse.swt.widgets.Control content)
- Set the content that will be scrolled.
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 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
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 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
public void setLayout(org.eclipse.swt.widgets.Layout layout)
- Description copied from class:
org.eclipse.swt.widgets.Composite - Sets the layout which is associated with the receiver to be
the argument which may be null.
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.
setMinSize
public 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. This value is only relevant if
setExpandHorizontal(true) and setExpandVertical(true) have been set.
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.
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.
vScroll
void vScroll()
|
|||||||||
| Home >> All >> org >> eclipse >> swt >> [ custom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC