Ich hatte diese Woche ein Problem, mit der „ListActionView“ von und der „JFXProgessBar“ von „JFoenix“, das ich nur bedingt lösen konnte.
Problembeschreibung
Immer wenn ich die ProgessBar von „JFoenix“ und die „ListActionView“ von „ControlsFX“ implementiert habe, bekam ich folgende Exception:
java.lang.ExceptionInInitializerError
at M_Registraturplan/rp.controller.admin.parents.CListActionViewMenuPos.createActions(CListActionViewMenuPos.java:111)
at M_Registraturplan/rp.controller.admin.parents.CListActionViewMenuPos.setListActionViewMenuPos(CListActionViewMenuPos.java:75)
at M_Registraturplan/rp.controller.admin.parents.CListActionViewMenuPos.<init>(CListActionViewMenuPos.java:56)
at M_Registraturplan/rp.controller.admin.parents.CLayout.set(CLayout.java:751)
at M_Registraturplan/rp.parents.PLayout.<init>(PLayout.java:50)
at M_Registraturplan/rp.controller.admin.CMainSuperAdmin.addTabLayout(CMainSuperAdmin.java:276)
at M_Registraturplan/rp.controller.admin.CMainSuperAdmin.set(CMainSuperAdmin.java:369)
at M_Registraturplan/rp.stage.admin.StageMainSuperAdmin.lambda$0(StageMainSuperAdmin.java:71)
at M_Registraturplan/rp.stage.splashScreenAfterLogin.SplashScreenAfterLogin.call(SplashScreenAfterLogin.java:186)
at M_Registraturplan/rp.stage.splashScreenAfterLogin.SplashScreenAfterLogin.call(SplashScreenAfterLogin.java:1)
at javafx.graphics/javafx.concurrent.Task$TaskCallable.call(Task.java:1425)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.RuntimeException: Cannot add UserAgentStylesheet as the method is not accessible
at org.controlsfx.controls/impl.org.controlsfx.ReflectionUtils.addUserAgentStylesheet(ReflectionUtils.java:231)
at org.controlsfx.controls/org.controlsfx.glyphfont.GlyphFont.<clinit>(GlyphFont.java:57)
... 13 moreCode-Sprache: HTML, XML (xml)
Wenn ich aber die ProgessBar von „JavaFX“ implementiert habe und nicht die von „JFoenix“, hatte ich keine Probleme.
Ich habe mit etwas mit den „VM arguments“ rumgespielt, aber ohne Erfolg. Hier meine VM arguments:
--module-path "C:\Program Files\Java\java-11\javafx-sdk-11.0.2\lib" --add-modules=javafx.controls,javafx.fxml,javafx.base,javafx.graphics
--add-exports=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls
--add-exports=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls
--add-exports=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls
--add-exports=javafx.controls/com.sun.javafx.scene.control=org.controlsfx.controls
--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls
--add-exports=javafx.controls/com.sun.javafx.scene.control.inputmap=org.controlsfx.controls
--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls
--add-exports=javafx.base/com.sun.javafx.collections=org.controlsfx.controls
--add-exports=javafx.base/com.sun.javafx.runtime=org.controlsfx.controls
--add-opens=javafx.controls/javafx.scene.control.skin=org.controlsfx.controls
--add-exports=javafx.web/com.sun.webkit=org.controlsfx.controls
--add-exports javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix
--add-exports javafx.controls/com.sun.javafx.scene.control=com.jfoenix
--add-exports javafx.base/com.sun.javafx.binding=com.jfoenix
--add-exports javafx.graphics/com.sun.javafx.stage=com.jfoenix
--add-exports=javafx.graphics/com.sun.javafx.css=com.jfoenix
--add-exports javafx.base/com.sun.javafx.event=com.jfoenix
--add-opens javafx.graphics/com.sun.javafx.scene=com.jfoenix
--add-opens=javafx.controls/javafx.scene.control.skin=com.pixelduke.fxskinsCode-Sprache: JavaScript (javascript)
Das Problem wurde unter anderem durch die Verwendung von „new FontAwesome().create(FontAwesome.Glyph.ANGLE_UP)“ im folgendem Code verursacht:
ListActionView view = new ListActionView<>();
view.getItems().add("One", "Two", "Three");
view.getActions().add(new ListActionView.ListAction() {
new FontAwesome().create(FontAwesome.Glyph.ANGLE_UP)
@Override
public void initialize(ListView listView) {
setEventHandler(e -> System.out.println("Action fired!"));
}
});
view.getActions().add(ActionUtils.ACTION_SEPARATOR);Code-Sprache: JavaScript (javascript)
Wenn ich das Icon von „FontAwesome“ nicht implementiert habe, dann gab es auch keine Exception.
Ich konnte das Problem auch nicht in einem kleinem Beispiele reproduzieren, die Exception gab es nur in meinem aktuellem Projekt.
Lösung
Meine Lösung war, das ich auf die Verwendung von „FontAwesome“ verzichtet habe, ich wollte aber nicht auf ein Icon verzichten und ersetzte das Icon durch ein „Unicode Zeichen“, mit hilfe von Apache Commons Lang, wie man im folgendem Code sehen kann. Die VBox dient nur als Platzhalter für die Klasse von „ListAction“.
Code mit der Lösung
ListActionView view = new ListActionView<>();
view.getItems().add("One", "Two", "Three");
view.getActions().add(new ListActionView.ListAction() {
new VBox(), StringEscapeUtils.unescapeJava("\\u25B2")
@Override
public void initialize(ListView listView) {
setEventHandler(e -> System.out.println("Action fired!"));
}
});
view.getActions().add(ActionUtils.ACTION_SEPARATOR);Code-Sprache: JavaScript (javascript)
- Pfeil nach oben = StringEscapeUtils.unescapeJava(„\u25B2“)
- Pfeil nach unten = StringEscapeUtils.unescapeJava(„\u25BC“)
Bei der Klasse „ListAction“ kann man ein „Node graphic“ als Parameter mitgeben, ich habe versucht ein Label, Icon, ImageView, Text usw. zu implementieren, aber nichts davon wurde mir angezeigt, das einzige was funktioniert hat, war die oben genannte Lösung.
Klasse „ListAction“ von „ControlsFX“
public static abstract class ListAction<T> extends Action {
/**
* Creates a new instance of ListAction with the graphic node.
* @param graphic Graphic to be shown in relation to this action.
*/
public ListAction(Node graphic) {
this(graphic, "");
}
/**
* Creates a new instance of ListAction with the provided graphic and text.
* @param graphic Graphic to be shown in relation to this action.
* @param text The text for the Action.
*/
public ListAction(Node graphic, String text) {
super(text);
setGraphic(graphic);
}
/**
* Can be used to define properties or bindings for actions
* which are directly dependent on the list view.
* @param listView The list view
*/
public abstract void initialize(ListView<T> listView);
@Override
protected final void setEventHandler(Consumer<ActionEvent> eventHandler) {
super.setEventHandler(eventHandler);
}
}Code-Sprache: PHP (php)