Java Reference
In-Depth Information
Scene scene = new Scene(vBox, 210, 210);
canvas.setScene(scene);
rectangle.fillProperty().bind(model.fillProperty());
rectangle.strokeProperty().bind(model.strokeProperty());
We also changed the model into a JavaFX bean. The event listeners are changed in a natural way. The complete
SWT JavaFX hybrid program is shown in Listing 7-14.
Listing 7-14. JavaFXSceneInSWTExample.java
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.embed.swt.FXCanvas;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class JavaFXSceneInSWTExample {
public static void main(final String[] args) {
Model model = new Model();
View view = new View(model);
Controller controller = new Controller(model, view);
controller.mainLoop();
}
private static class Model {
private ObjectProperty<Color> fill = new SimpleObjectProperty<>(Color.LIGHTGRAY);
private ObjectProperty<Color> stroke = new SimpleObjectProperty<>(Color.DARKGRAY);
public Color getFill() {
return fill.get();
}
public void setFill(Color value) {
this.fill.set(value);
}
 
Search WWH ::




Custom Search