如何在布局中添加 Richfx
How to add Richfx in a layout
我一直在尝试在 javafx 的主要方法和 fxml 文件中的 anylayout 中添加一个 InlineStyleTextArea 和一个 CodeArea。我收到线程错误。如果可能的话,请举例说明如何将这些组件添加到 javafx 布局中?如果可能,请提供教程 link.
这是一个简单的代码
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
TextField myTextField = new TextField();
InlineCssTextArea TextArea = new InlineCssTextArea();
HBox hbox = new HBox();
hbox.getChildren().add(myTextField);
hbox.getChildren().add(TextArea);
HBox.setHgrow(myTextField, Priority.ALWAYS);
HBox.setHgrow(TextArea, Priority.ALWAYS);
Scene scene = new Scene(hbox);
primaryStage.setScene(scene);
primaryStage.show();}
public static void main(String[] args) {
launch(args);
}
}
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication2(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/reactfx/value/SuspendableVal
at application.Main.start(Main.java:20)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication19(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda/19776028.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait2(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda/18503843.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null0(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda/3799573.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater1(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda/2180324.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null5(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda/3326003.run(Unknown Source)
... 1 more
Caused by: java.lang.ClassNotFoundException: org.reactfx.value.SuspendableVal
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
Exception running application application.Main
at com.sun.javafx.application.LauncherImpl$$Lambda/14845382.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
从堆栈跟踪来看,Java 运行时似乎找不到(至少 class 中的一个)ReactFX 库,它是 RichTextFX 的依赖项。由于它一直在寻找那个,它一定已经找到 InlineCssTextArea
,因此必须安装 RichTextFX 库。
如果您使用某种依赖管理(例如 Gradle 或 Maven),该工具应该为您管理所有依赖。
如果您手动管理依赖项(即下载 jar 文件并将它们添加到 class 路径),您需要确保同时下载所有依赖的 jar 文件,或者使用"Fat jar file".
我一直在尝试在 javafx 的主要方法和 fxml 文件中的 anylayout 中添加一个 InlineStyleTextArea 和一个 CodeArea。我收到线程错误。如果可能的话,请举例说明如何将这些组件添加到 javafx 布局中?如果可能,请提供教程 link.
这是一个简单的代码
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
TextField myTextField = new TextField();
InlineCssTextArea TextArea = new InlineCssTextArea();
HBox hbox = new HBox();
hbox.getChildren().add(myTextField);
hbox.getChildren().add(TextArea);
HBox.setHgrow(myTextField, Priority.ALWAYS);
HBox.setHgrow(TextArea, Priority.ALWAYS);
Scene scene = new Scene(hbox);
primaryStage.setScene(scene);
primaryStage.show();}
public static void main(String[] args) {
launch(args);
}
}
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication2(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/reactfx/value/SuspendableVal
at application.Main.start(Main.java:20)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication19(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda/19776028.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait2(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda/18503843.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null0(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda/3799573.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater1(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda/2180324.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null5(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda/3326003.run(Unknown Source)
... 1 more
Caused by: java.lang.ClassNotFoundException: org.reactfx.value.SuspendableVal
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
Exception running application application.Main
at com.sun.javafx.application.LauncherImpl$$Lambda/14845382.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
从堆栈跟踪来看,Java 运行时似乎找不到(至少 class 中的一个)ReactFX 库,它是 RichTextFX 的依赖项。由于它一直在寻找那个,它一定已经找到 InlineCssTextArea
,因此必须安装 RichTextFX 库。
如果您使用某种依赖管理(例如 Gradle 或 Maven),该工具应该为您管理所有依赖。
如果您手动管理依赖项(即下载 jar 文件并将它们添加到 class 路径),您需要确保同时下载所有依赖的 jar 文件,或者使用"Fat jar file".