Java Reference
In-Depth Information
public void mainLoop() {
view.frame.setVisible(true);
}
}
}
When the program in Listing 7-12 is run, the GUI in Figure 7-18 is displayed. You can't tell from the screenshot,
but the rectangle in the center of the JFrame is a JavaFX rectangle.
Figure 7-18. The JavaFXSceneInSwingExample program
Embedding JavaFX Scenes in SWT Applications
JavaFX is capable of embedding a JavaFX scene into an SWT application through the javafx.embed.swt
package of classes. It contains two public classes, FXCanvas and SWTFXUtils . The FXCanvas class extends
org.eclipse.swt.widgets.Canvas , and can be placed in an SWT program just like any other SWT widget. FXCanvas
can also host a JavaFX scene, and can add a JavaFX scene to an SWT program.
Because both SWT and JavaFX use the native platform's UI thread as their own event dispatching thread, the SWT
UI thread (where a Display object is instantiated and where the main loop is started and where all other UI widgets must
be created and accessed) and the JavaFX application thread are one and the same. Therefore there is no need to use
Platform.runLater() or its SWT equivalent display.asyncExec() in your SWT and JavaFX event handlers.
The SWT program in Listing 7-13 is an SWT port of the Swing program in Listing 7-11.
Listing 7-13. NoJavaFXSceneInSWTExample.java
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
 
Search WWH ::




Custom Search