Java Reference
In-Depth Information
When the program in Listing 7-13 is run, the UI in Figure 7-19 is displayed. It is an SWT Shell holding four SWT
widgets, a Canvas with a PaintListener that makes it look like the rectangle we saw earlier, two Button s that will
change the fill and the stroke of the rectangle, and a Label widget that will show the location of the mouse pointer
when the mouse is inside the rectangle.
Figure 7-19. The NoJavaFXSceneInSWTExample program
As we did with the Swing example, we replace the custom painted Canvas widget in the program
NoJavaFXSceneInSWTExample with a JavaFX Rectangle . This is done by replacing the SWT code with the equivalent
FXCanvas code. Here is the SWT code:
canvas = new Canvas(canvasPanel, SWT.NONE);
canvas.setLayoutData(new RowData(200, 200));
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent paintEvent) {
final GC gc = paintEvent.gc;
final Color strokeColor = new Color(display, model.strokeColor);
gc.setBackground(strokeColor);
gc.fillRectangle(0, 0, 200, 200);
final Color fillColor = new Color(display, model.fillColor);
gc.setBackground(fillColor);
gc.fillRectangle(10, 10, 180, 180);
strokeColor.dispose();
fillColor.dispose();
}
});
And here is the FXCanvas code:
canvas = new FXCanvas(canvasPanel, SWT.NONE);
rectangle = new Rectangle(200, 200);
rectangle.setStrokeWidth(10);
VBox vBox = new VBox(rectangle);
 
Search WWH ::




Custom Search