0% found this document useful (0 votes)
17 views22 pages

swt4 Controls2

This document provides an overview of various controls available in the SWT widget toolkit, including container controls like ToolBar and CoolBar, non-container controls like ToolItem and Separator, and other controls like ProgressBar, Canvas, Scale, Slider, Browser, Link, ExpandBar, StyledText, DragSource, and DropTarget. Code examples are provided for constructing and configuring each control.

Uploaded by

Desire Goore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views22 pages

swt4 Controls2

This document provides an overview of various controls available in the SWT widget toolkit, including container controls like ToolBar and CoolBar, non-container controls like ToolItem and Separator, and other controls like ProgressBar, Canvas, Scale, Slider, Browser, Link, ExpandBar, StyledText, DragSource, and DropTarget. Code examples are provided for constructing and configuring each control.

Uploaded by

Desire Goore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

CHPT4.

CONTROLS-2
4. CONTROL
Control is the user interface element that
we can see on the user interface. It can be
divided into container controls and non-
container controls. Container controls can
contain other container controls or non-
container controls, thus forming a
hierarchical relationship tree of control.

In the last lesson, we have introduced the


use of some controls
CONTROLS OVERVIEW
The org.eclipse.swt.widgets package defines the core components of SWT. In addition to the
controls introduced last time, the rest are as follows :
· ToolBar · ToolItem · Check ToolItem · Radio
ToolItem
· DropDown ToolItem · Separator ToolItem · CoolBar · CoolItem
· Horizontal Separator · Vertical Separator · ProgressBar · Canvas
· Scale · Slider · Browser · Link
· ExpandBar · ExpandItem · CLabel · CCombo
· StyledText · DragSource · DropTarget · TrayItem
4.1 TOOLBAR & TOOLITEM
ToolBar: The container control, it can contain multiple toolbar items.

ToolItem: A normal style toolbar button, representing an item of the toolbar.


Check ToolItem : Check box style toolbar button.
Radio ToolItem : A radio button-style toolbar button, also exclusive.
DropDown ToolItem : Drop-down style toolbar button, used with the Menu
control.
Separator ToolItem : The toolbar button of the separator effect.
before

4.1 TOOLBAR & TOOLITEM


ToolBar: ToolBar toolBar = new ToolBar(shell, SWT.BORDER);
toolBar.setLocation(int, int);

separator
ToolItem: ToolItem saveItem = new ToolItem(toolBar, SWT.PUSH);
saveItem.setText(String);
after click
saveItem.setToolTipText(String);

Separator ToolItem:
ToolItem tltmTool = new ToolItem(toolBar, SWT.SEPARATOR);
tltmTool.setWidth(int);

Here's the code


4.2 COOLBAR & COOLITEM
Many applications have multiple toolbars, and
CoolBar
toolbars can be dragged to different positions (such
as from the top of the window to the bottom), or CoolItem CoolItem
even dragged away from the original position to
become a separate window, and the tools in the setControl 方法

toolbar can be rearranged, etc.


ToolBar ToolBar

ToolItem ToolItem
The dynamic toolbar (CoolBar) provided by SWT
ToolItem ToolItem
has similar characteristics. Users can rearrange
toolbars or tool items (CoolItem) in the dynamic
toolbar, drag the separator between toolbars or tool
items, and for the dynamic toolbar. Control how the
toolbar or tool items wrap and the order in which the
tool items are displayed.
4.2 COOLBAR & COOLITEM
CoolBar: CoolBar coolBar = new CoolBar(shell, SWT.FLAT);
CoolItem: CoolItem coolItem = new CoolItem(coolBar, SWT.BORDER);
coolItem.setMinimumSize(new Point(int, int));
ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT |
SWT.RIGHT);
setControl: coolItem.setControl(toolBar);

after dragging

Here's the code


4.3 SEPARATOR
The separators provided by SWT are divided into horizontal separators and
vertical separators.
Users can choose it freely and no text can be displayed on the separators.

Example:
Label label=newLabel(shell, SWT.SEPARATOR|
SWT.HORIZONTAL);
label.setToolTipText("Horizontal Separator");
4.4 PROGRESS BAR
When the computer is processing for a long time without interacting with the user, the
progress bar provides gradual changes to tell the user that the system is not deadlocked,
and displays the current processing progress and the remaining workload or time in real
time.

Example:
ProgressBar pb1 = new ProgressBar(shell, SWT.SMOOTH);
pb1.setBounds(int, int, int, int); min selection max
pb1.setMinimum(int);
pb1.setMaximum(int);
pb1.setSelection(int);
4.5 CANVAS
The canvas provided by SWT gives us a surface for drawing arbitrary
graphics.

Example:
Canvas canvas = new Canvas(shell, SWT.BORDER);

Image image = new Image(display, url);


canvas.setBackgroundImage(image);
4.6 SCALE
Scale are used in GUI programs to allow the user to pick a value within a (usually
small) range of integers.

Example:
 Scale scale = new Scale(shell, SWT.BORDER);

Set the value range of the scale:


 scale.setMinimum(int);
 scale.setMaximum(int);

Sets the value by which a tick unit is incremented:


 scale.setPageIncrement(int);
4.7 SLIDER
Slider is visual components that displays a range of values. Most of the
properties of the slider are the same as the scale, and have the same meaning.
The difference is that slider provides a draggable object that can calibrate the
current value.

Note : The unique property to set the size of the slider. If the setting value is
less than 1, the setting value is ignored, if it exceeds the range of the slider,
the slider is not displayed.
Example:
Slider slider = new Slider(shell, SWT.BORDER);
slider.setThumb(20);
4.8 BROWSER
The Browser component of SWT provides popular HTML rendering engines:
IE on MS, Mozilla on Linux, and Safari on Mac.This component can
interpret, visually display and navigate HTML (web page) documents.

url is a unique property of this component that sets the URL for the browser
to load and process resources.

Example:
Browser browser = new Browser(shell, SWT.NONE);
browser.setUrl(String url);
4.9 LINK
The Link is similar to the PUSH button, but looks more like a text link in a
web browser.
Link only supports text content, where the text is specified by the text
attribute. it can be plain text or HTML A tags.

Example:
Link link = new Link(shell, SWT.NONE); before

link.setText(String);

Here's the code


after click
4.10 EXPANDBAR &
EXPANDITEM
ExpandBar: Supports the layout of selectable expand bar items.
ExpandItem: Represents a selectable user interface object that represents
a expandable item in a ExpandBar.

Example:
ExpandBar expandBar = new ExpandBar(shell, SWT.NONE);
ExpandItem xpndtmItem = new ExpandItem(expandBar, SWT.NONE);
xpndtmItem.setExpanded(true);
xpndtmItem.setText("item1");
Label lblIabel = new Label(expandBar, SWT.NONE);
xpndtmItem.setControl(lblIabel);
4.11 CLABEL
CLabel: A Label which supports aligned text and/or an image and different
border styles.

Example:
CLabel cl = new CLabel(shell, SWT.LEFT);
cl.setText(" 这是一个带有图标的自定义标签 ");
cl.setImage(new Image(shell.getDisplay(), url));
4.12 CCOMBO
The CCombo class represents a selectable user interface object that combines
a text field and a list.
Users can input freely or select a item directly from the list.

Example:
CCombo combo = new CCombo(shell, SWT.BORDER);
combo.add("item 1");
combo.add("item 2");
...
COMBO VS CCOMBO
4.13 STYLEDTEXT
A StyledText is an editable user interface object that displays lines of text.
Users can change font style, foreground and background colors of StyledText
and so on.

Example:
StyledText text = new StyledText(shell, SWT.BORDER);
text.setText(String);
4.14 DRAGSOURCE &
DROPTARGET
DragSource defines the source object for a drag and drop transfer.
DropTarget defines the target object for a drag and drop transfer.

Example:
Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
DragSource source = new DragSource (label, operations);
source.setTransfer(types); Click and drag
DropTarget target = new DropTarget(label, operations);
target.setTransfer(types);

Here's the code


4.15 TRAYITEM
Constructs a new instance of this class given its parent (which must be a
Tray) and a style value describing its behavior and appearance. The item is
added to the end of the items maintained by its parent.

Example:
Tray tray = display.getSystemTray();
TrayItem item = new TrayItem(tray, SWT.NONE);
item.setImage(...)
item.addListener(..., listener);

Here's the code


Any Question ?

You might also like