JavaFX
JavaFX is not in the JDK.
JavaFX is not in the JDK. jJavaFX(cVersion) downloads the jars of this computer's platform (javafx-base, javafx-graphics, javafx-controls; jJavaFXModules adds fxml, media, web, swing), starts the toolkit and puts the program in GUI mode, as jGui() does for Swing (see Windows and events): the calls of Ring run on the JavaFX application thread and the event functions run on the Ring thread in jMainLoop().
load "java.ring"
jJavaFX("21.0.2")
jJavaFXClasses("21.0.2") # the Ring classes of javafx.* (made once)
using {
"javafx.stage"
"javafx.scene"
"javafx.scene.control"
"javafx.scene.layout"
}
oButton = new Button("Click me")
oButton.setOnAction("onClick")
oStage = new Stage
oStage.setScene((new Scene).@New([ new StackPane(oButton) , 320 , 160 ]))
oStage.show()
jMainLoop()
func onClick aArgs
oButton.setText("Clicked")
| Function | Meaning |
|---|---|
jJavaFX(cVersion) | download, class path, toolkit, GUI mode |
jJavaFXClasses(cVersion) | the Ring classes of the javafx.* packages |
jJavaFXModules(aModules) | the modules to download (before jJavaFX) |
jFXRunLater(cFunction) | Platform.runLater with a Ring function |
jFXMessage(cText) | an Alert message |
jMainLoop(), jStopLoop() and jAutoClose() work for JavaFX windows too. JavaFX runs from the class path (the "unsupported configuration" warning of the JavaFX launcher does not apply because the toolkit is started with Platform.startup). Platform.setImplicitExit(false) is set so that closing the last window does not stop the toolkit.
Custom controls and Application subclasses need Java code (Ring cannot subclass a Java class); everything that is built from the existing classes and listeners works.
Notes#
- Plain class names are used (
Label,Button); a name that clashes with a JDK class gets a prefix, for exampleShapePath(javafx.scene.shape.Path) andBeansObservable. - Do not mix
java.awt/javax.swingclasses withjavafx.scene.controlin one program:jImportraises an error for the clash. - JavaFX prints a warning "Unsupported JavaFX configuration" because the jars are on the class path, not the module path; it is harmless.
- Events run on the Ring thread and calls made from them go to the JavaFX thread, so
oLabel.setText(...)in a handler is safe. - Set
RINGJAVA_AUTOCLOSE=1500to close the windows by themselves (used by the samples and tests).