为什么我不能在 scenebuilder 中 select JFXTextfield 并添加它

Why can't i select JFXTextfield in scenebuilder and add it

JFTTextAreaJFXButton 有效,但为什么 JFXTextField?

我添加了 foenix 库,所以我得到了所有的 JFXTextField 但是我无法将 JFXTextField 放在 SceneBuilder 中!!

这里我在项目结构中添加了库。

如果我在文本模式的sample.xml中强行添加JFXTextField, 它不显示编译器错误 而是显示

Unable to make boolean java.lang.reflect.AccessibleObject.setAccessible0(boolean) accessible: module java.base does not "opens java.lang.reflect" to module com.jfoenix

完整的错误如下所示:

java.lang.reflect.InaccessibleObjectException: Unable to make boolean java.lang.reflect.AccessibleObject.setAccessible0(boolean) accessible: module java.base does not "opens java.lang.reflect" to module com.jfoenix
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
    at com.jfoenix/com.jfoenix.adapters.ReflectionHelper.<clinit>(ReflectionHelper.java:48)
    at com.jfoenix/com.jfoenix.skins.JFXTextFieldSkin.<init>(JFXTextFieldSkin.java:59)
    at com.jfoenix/com.jfoenix.controls.JFXTextField.createDefaultSkin(JFXTextField.java:69)
    at javafx.controls/javafx.scene.control.Control.doProcessCSS(Control.java:897)
    at javafx.controls/javafx.scene.control.Control.doProcessCSS(Control.java:89)
    at javafx.controls/com.sun.javafx.scene.control.ControlHelper.processCSSImpl(ControlHelper.java:67)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:145)
    at javafx.graphics/javafx.scene.Parent.doProcessCSS(Parent.java:1400)
    at javafx.graphics/javafx.scene.Parent.doProcessCSS(Parent.java:125)
    at javafx.graphics/com.sun.javafx.scene.ParentHelper.processCSSImpl(ParentHelper.java:98)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:145)
    at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9547)
    at javafx.graphics/javafx.scene.Scene.doCSSPass(Scene.java:569)
    at javafx.graphics/javafx.scene.Scene.preferredSize(Scene.java:1747)
    at javafx.graphics/javafx.scene.Scene.preferredSize(Scene.java:393)
    at javafx.graphics/com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)
    at javafx.graphics/javafx.stage.Window.invalidated(Window.java:1111)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
    at javafx.graphics/javafx.stage.Window.setShowing(Window.java:1187)
    at javafx.graphics/javafx.stage.Window.show(Window.java:1202)
    at javafx.graphics/javafx.stage.Stage.show(Stage.java:273)
    at Material.Design.Scene.Builder/sample.Main.start(Main.java:16)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait(PlatformImpl.java:474)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:447)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:446)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:831)
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.NullPointerException: Cannot invoke "javafx.scene.Node.getLayoutBounds()" because "this.textNode" is null
    at com.jfoenix/com.jfoenix.skins.JFXTextFieldSkin.updateTextPos(JFXTextFieldSkin.java:109)
    at com.jfoenix/com.jfoenix.skins.JFXTextFieldSkin.layoutChildren(JFXTextFieldSkin.java:93)
    at javafx.controls/javafx.scene.control.Control.layoutChildren(Control.java:601)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1207)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Scene.doLayoutPass(Scene.java:576)
    at javafx.graphics/javafx.scene.Scene.preferredSize(Scene.java:1750)
    at javafx.graphics/javafx.scene.Scene.preferredSize(Scene.java:393)
    at javafx.graphics/com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)
    at javafx.graphics/javafx.stage.Window.invalidated(Window.java:1111)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
    at javafx.graphics/javafx.stage.Window.setShowing(Window.java:1187)
    at javafx.graphics/javafx.stage.Window.show(Window.java:1202)
    at javafx.graphics/javafx.stage.Stage.show(Stage.java:273)
    at Material.Design.Scene.Builder/sample.Main.start(Main.java:16)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait(PlatformImpl.java:474)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:447)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:446)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop(WinApplication.java:174)
    ... 1 more
Exception running application sample.Main

Process finished with exit code 1

我什至试过这个 link 但是不能很好地连接:(

我的sample.xml是这样的:

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <children>
      <Button fx:id="button" layoutX="494.0" layoutY="187.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="74.0" text="Button" />
      <TextField fx:id="textField" layoutX="44.0" layoutY="140.0" />
      <JFXTextField fx:id="textField1" layoutX="433.0" layoutY="140.0" promptText="Type in here">
         <effect>
            <InnerShadow />
         </effect></JFXTextField>
      <JFXTextField />
      <JFXTextArea fx:id="JFXtextArea" layoutX="51.0" prefHeight="116.0" prefWidth="518.0" />
      <TextArea fx:id="textArea" layoutX="51.0" layoutY="245.0" prefHeight="130.0" prefWidth="518.0" />
      <JFXButton fx:id="buutton" layoutX="44.0" layoutY="187.0" prefHeight="26.0" prefWidth="99.0" text="Button">
   </children>
</AnchorPane>
      

我有最新版本的 java,我正在使用最新版本的 JFoenix,我得到的是相同的 InaccessibleObjectException 和你一样。他们这边好像有问题,我刚刚联系了他们,我们得等他们修好了。 Link 问题:Not able to add JFXTextField in Scene Builder 16.0.0 #1205

我在使用 SceneBuilder 16.0 和 JFoenix 9.0.10 时遇到了同样的问题。我尝试的解决方案是使用早期版本的 SceneBuilder,我下载了 SceneBuilder 11.0 并且有效。

JFoenix 尚未修正此错误。

经过多次研究,我终于找到了答案,

答案是,JFonenix 还不兼容更新后的 jdk 因为它只与 Jdk 1.8 兼容,即 JAVA SE 8th edition

让项目选择jdk 1.8,然后就可以了:)

下载Java 8 从下面这个link

https://www.oracle.com/in/java/technologies/javase/javase8-archive-downloads.html

已下载 SceneBuilder 15.0.0 并使用 JFoenix 9.0.10 并使用 java-sdk-15.0.1 和 java jdk 15.0.0 或 jdk 15.0.1 并在您的参数 VM 中添加以下设置:

--add-exports javafx.graphics/com.sun.javafx.scene=com.jfoenix --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.base/com.sun.javafx.event=com.jfoenix --add-exports javafx.graphics/com.sun.javafx.stage=com.jfoenix --add-opens=java.base/java.lang.reflect=com.jfoenix

对于任何 jdk/scenebuilder 版本,请使用 jfoenix 9.0.1 而不是 marven 的 9.0.10。它对我有用