@FxView
@FxView
allows usage of conventional FX Views.
The goal is to have automatic FXML loading, as well i18n bundle resources just by using the io.quarkiverse.fx.views.FxView
annotation, based on naming convention.
Naming conventions
Marking an FX controller with such annotation allows for automatic load of :
-
the corresponding
.fxml
-
the
.properties
resource bundle (if any)
By default, the filename is deduced from the controller class name.
For a controller class MySampleController
, the extension will attempt to load :
-
MySample.fxml
-
MySample.properties
or a resource corresponding to current locale such asMySample_fr_CA.properties
for instance
The Controller
suffix is removed when deducing the filename. From a controller class named MySample
, same filenames will be retrieved, though it is recommended as a convention to keep the Controller
suffix.
Also, it is possible to use a custom filename : @FxView("my-custom-name")
will attempt to load files my-custom-name.fxml
and resource bundle with name my-custom-name
.
Directory lookup
By default, files are retrieved from the classpath root.
Therefore, files directly located under src/main/resources
will be retrieved.
It can be customised by specifying the property fx-views-root
(/
by default).
If we define this property with value views
:
fx-views-root=views
Our project could look like this :
src/ └── main/ └── resources/ └── views/ ├── Home.fxml ├── Home.css ├── Home.properties ├── About.fxml ├── About.css └── About.properties
(Stylesheets can use different names)
If the view is not found in the root directory, it will look under the subdirectory corresponding to the view name, allowing to have a better organized application (one directory per view).
src/ └── main/ └── resources/ └── views/ ├── Home/ │ ├── Home.fxml │ ├── Home.css │ └── Home.properties └── About/ ├── About.fxml ├── About.css └── About.properties
Samples
Some code examples can be found under samples/fxviews
.
@FxView
@Dependent
public class SampleController {
@FXML
private void onButtonClick() {
System.out.println("onButtonClick");
}
}
Stylesheet live reload
It is possible to enable automatic live reload for stylesheets (.css
files).
The live reload strategy can be configured with the property quarkus.fx.stylesheet-reload-strategy
.
Possibles values are :
-
NEVER
: never live reload stylesheets -
DEV
: live reload is enabled in dev mode -
ALWAYS
: live reload is always enabled
When live reload is active, any change made to a stylesheet file in the source directory will be immediately applied.
The properties quarkus.fx.source-resources
(default: src/main/resources/
) and quarkus.fx.target-resources
(default: target/classes/
) define the source and target directories, enabling the stylesheet in the source directory to replace the one in use.
src/ └── main/ └── resources/ └── views/ └── Home/ └── Home.css target/ └── classes/ └── views/ └── Home/ └── Home.css
The utility class StylesheetWatchService
can also be used to set up live reload explicitly.
StylesheetWatchService.setStyleAndStartWatchingTask(() -> component.getStylesheets(), path);