Class ButtonFactory
Button. This offers several benefits over creating with widget the
 normal way:
 - The same factory can be used many times to create several instances
- The setters all return "this", allowing them to be chained
- The onSelect(java.util.function.Consumer<org.eclipse.swt.events.SelectionEvent>)) accepts a Lambda forSelectionEvent
 Button button = ButtonFactory.newButton(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 = ButtonFactory.newButton(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 widget.
- Since:
- 3.18
- 
Method SummaryModifier and TypeMethodDescriptionSets the receiver's image to the argument, which may benullindicating that no image should be displayed.static ButtonFactorynewButton(int style) Creates a new ButtonFactory with the given style.onSelect(Consumer<SelectionEvent> consumer) Creates aSelectionListenerand registers it for the widgetSelected event.Sets the receiver's text.Methods inherited from class org.eclipse.jface.widgets.AbstractControlFactorybackground, enabled, font, foreground, layoutData, orientation, supplyLayoutData, tooltipMethods inherited from class org.eclipse.jface.widgets.AbstractWidgetFactoryaddProperty, cast, create, data, data
- 
Method Details- 
newButtonCreates a new ButtonFactory with the given style. Refer toButton(Composite, int)for possible styles.- Returns:
- a new ButtonFactory instance
 
- 
textSets the receiver's text.This method sets the button label. The label may include the mnemonic character but must not contain line delimiters. Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. When the user presses a key sequence that matches the mnemonic, a selection event occurs. On most platforms, the mnemonic appears underlined but may be emphasized in a platform specific manner. The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single '&' to be displayed. - Parameters:
- text- the text
- Returns:
- this
- See Also:
 
- 
imageSets the receiver's image to the argument, which may benullindicating that no image should be displayed.- Parameters:
- image- the image to display on the receiver (may be- null)
- Returns:
- this
- See Also:
 
- 
onSelectCreates aSelectionListenerand registers it for the widgetSelected event. If the receiver is selected by the user the given consumer is invoked. TheSelectionEventis passed to the consumer.- Parameters:
- consumer- the consumer whose accept method is called
- Returns:
- this
- See Also:
 
 
-