Package org.eclipse.jface.widgets
Class WidgetFactory
java.lang.Object
org.eclipse.jface.widgets.WidgetFactory
This class provides a convenient shorthand for creating and initializing
factories for SWT widgets. This offers several benefits over creating SWT
widgets with the low level SWT API
- The same factory can be used many times to create several widget instances
- The setters can be chained
- Factories accept a lambda whenever applicable
Button button = WidgetFactory.button(SWT.PUSH) // .text("Click me!") // .onSelect(event -> buttonClicked(event)) // .layoutData(gridData) // .create(parent);
The above example creates a push button with a text, registers a SelectionListener and finally creates the button in "parent".
GridDataFactory gridDataFactory = GridDataFactory.swtDefaults(); ButtonFactory buttonFactory = WidgetFactory.button(SWT.PUSH).onSelect(event -> buttonClicked(event)) .layout(gridDataFactory::create); buttonFactory.text("Button 1").create(parent); buttonFactory.text("Button 2").create(parent); buttonFactory.text("Button 3").create(parent);
The above example creates three buttons using the same instance of ButtonFactory. Note the layout method. A Supplier is used to create unique GridData for every single button.
- Since:
- 3.18
-
Method Summary
Modifier and TypeMethodDescriptionstatic BrowserFactory
browser
(int style) static ButtonFactory
button
(int style) static CompositeFactory
composite
(int style) static DateTimeFactory
dateTime
(int style) static GroupFactory
group
(int style) static LabelFactory
label
(int style) static SashFactory
sash
(int style) static SashFormFactory
sashForm
(int style) static ShellFactory
shell
(int style) static SpinnerFactory
spinner
(int style) static TableFactory
table
(int style) static TableColumnFactory
tableColumn
(int style) static TextFactory
text
(int style) static TreeFactory
tree
(int style) static TreeColumnFactory
treeColumn
(int style)
-
Method Details
-
button
- Parameters:
style
- SWT style applicable for Button. Refer toButton(Composite, int)
for supported styles.- Returns:
- ButtonFactory
-
text
- Parameters:
style
- SWT style applicable for Text. Refer toText(Composite, int)
for supported styles.- Returns:
- TextFactory
-
label
- Parameters:
style
- SWT style applicable for Label. Refer toLabel(Composite, int)
for supported styles.- Returns:
- LabelFactory
-
composite
- Parameters:
style
- SWT style applicable for Composite. Refer toComposite(Composite, int)
for supported styles.- Returns:
- CompositeFactory
-
dateTime
- Parameters:
style
- SWT style applicable for DateTime. Refer toDateTime(Composite, int)
for supported styles.- Returns:
- DateTimeFactory
- Since:
- 3.22
-
spinner
- Parameters:
style
- SWT style applicable for Spinner. Refer toSpinner(Composite, int)
for supported styles.- Returns:
- SpinnerFactory
-
table
- Parameters:
style
- SWT style applicable for Table. Refer toTable(Composite, int)
for supported styles.- Returns:
- TableFactory
-
tree
- Parameters:
style
- SWT style applicable for Tree. Refer toTree(Composite, int)
for supported styles.- Returns:
- TreeFactory
-
tableColumn
- Parameters:
style
- SWT style applicable for TableColumn. Refer toTableColumn(Table, int)
for supported styles.- Returns:
- TableColumnFactory
-
treeColumn
- Parameters:
style
- SWT style applicable for TreeColumn. Refer toTreeColumn(Tree, int)
for supported styles.- Returns:
- TreeColumnFactory
-
sash
- Parameters:
style
- SWT style applicable for Sash. Refer toSash(Composite, int)
for supported styles.- Returns:
- SashFactory
- Since:
- 3.21
-
sashForm
- Parameters:
style
- SWT style applicable for SashForm. Refer toSashForm(Composite, int)
for supported styles.- Returns:
- SashFormFactory
- Since:
- 3.21
-
shell
- Parameters:
style
- SWT style applicable for Shell. Refer toShell(Shell, int)
for supported styles.- Returns:
- ShellFactory
- Since:
- 3.21
-
group
- Parameters:
style
- SWT style applicable for Group. Refer toGroup(Composite, int)
for supported styles.- Returns:
- GroupFactory
- Since:
- 3.24
-
browser
- Parameters:
style
- SWT style applicable for Browser. Refer toBrowser(Composite, int)
for supported styles.- Returns:
- BrowserFactory
- Since:
- 3.25
-