- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有主要的应用程序类,可以很好地完成以下任务:
@Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(
"RecordScreen.fxml"));
Parent root = (Parent) loader.load();
Scene newScene = new Scene(root);
Stage newStage = new Stage();
newStage.setScene(newScene);
newStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
@FXML
public void editPerson() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(
"PersonEditor.fxml"));
PersonEditorCtrl ctrl = loader.getController();
ctrl.init(table.getSelectionModel().getSelectedItem());
Parent root = (Parent) loader.load();
Scene newScene = new Scene(root);
Stage newStage = new Stage();
newStage.setScene(newScene);
newStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.RecordsCtrl">
<!-- TODO Add Nodes -->
<children>
<VBox id="VBox" alignment="CENTER" spacing="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<TableView fx:id="table" prefHeight="-1.0" prefWidth="-1.0">
<columns>
<TableColumn prefWidth="75.0" text="Name" fx:id="nameCol" />
<TableColumn prefWidth="75.0" text="Age" fx:id="ageCol" />
</columns>
</TableView>
<Button mnemonicParsing="false" onAction="#editPerson" text="Edit" />
</children>
</VBox>
</children>
</AnchorPane>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.PersonEditorCtrl">
<!-- TODO Add Nodes -->
<children>
<VBox layoutX="0.0" layoutY="0.0" prefHeight="-1.0" prefWidth="-1.0">
<children>
<TextField fx:id="nameField" prefWidth="200.0" />
<TextField fx:id="ageField" prefWidth="200.0" />
<Button mnemonicParsing="false" text="Button" />
</children>
</VBox>
</children>
</AnchorPane>
最佳答案
改变这个
@FXML
public void editPerson() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(
"PersonEditor.fxml"));
PersonEditorCtrl ctrl = loader.getController();
ctrl.init(table.getSelectionModel().getSelectedItem());
Parent root = (Parent) loader.load();
Scene newScene = new Scene(root);
Stage newStage = new Stage();
newStage.setScene(newScene);
newStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
@FXML
public void editPerson() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(
"PersonEditor.fxml"));
Parent root = (Parent) loader.load();
PersonEditorCtrl ctrl = loader.getController();
ctrl.init(table.getSelectionModel().getSelectedItem());
Scene newScene = new Scene(root);
Stage newStage = new Stage();
newStage.setScene(newScene);
newStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
loader.load()
,然后才能获取Controller。
关于javafx - FXMLLoader getController返回NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23461148/
尝试从 FXML 文件加载 Controller 时出现 LoadException。这是 FXML 文件:
我有主要的应用程序类,可以很好地完成以下任务: @Override public void start(Stage primaryStage) { try {
在“Pro JavaFX 8:构建桌面、移动和嵌入式 Java 客户端的权威指南”的第 3 章中,一个示例说明了如何直接在 FXML 文件中指定对象。 您可以在本文末尾找到完整的 FXML 文件以及示
在“Pro JavaFX 8:构建桌面、移动和嵌入式 Java 客户端的权威指南”的第 3 章中,一个示例说明了如何直接在 FXML 文件中指定对象。 您可以在本文末尾找到完整的 FXML 文件以及示
在学习Javafx时,我已经学习了舞台、场景和场景图(树数据结构)(分支节点、叶节点)等...所以我知道场景图的基础知识,它必须包含根节点及其子节点,并且场景类采用根节点类型的参数,所以我的问题是当我
这是我的第一个问题,所以如果我出错了,请耐心等待,但我对 FXMLLoader 有一个奇怪的问题,我无法解释自己,所以任何提示或帮助将不胜感激。 以下代码片段是我如何将文件 GraphicSettin
我有一个由根布局组成的 javaFX 界面,它是一个简单的 BorderPane。当在 rootLayout 菜单上按下按钮时,我想将两个 AnchorPane 交替设置在 rootLayout 的中
我正在寻找有关在 Swing 上下文中使用 FXML 的 JavaFX 2 的一些帮助。我使用 Scene Builder(版本:2.0-b10,变更集:48fc80a12d33)构建了一个场景,并试
我正在尝试运行本教程: http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm 我想在 Eclipse 上运行它。我从网
我在 fxml 文件的根级别有 ScrollPane,并且有以下代码: import javafx.scene.Parent; ... parent = (Parent)fxmlLoader.load
我有一个 JavaFx 项目,其中 Maven install 一直给我错误: [ERROR] Failed to execute goal org.apache.maven.plugins:mave
我正在尝试访问加载 fxml 的窗口的 Controller 类的实例。它加载时没有错误,但是当我尝试使用打印帐户数量时 System.out.println("from NAW: "+ NAC.ne
因此,我使用 JavaFX 的 Scene Builder 工具创建了一个 FXML 界面,并尝试通过我的代码加载它。但是,我在尝试加载 FXML 文档时遇到了此错误:FXMLLoader.load
我有一个用于整个应用程序的大型资源文件,因此如果我可以仅为整个 JavaFX 场景设置它,而不是每次执行 new FXMLLoader(...) 时,那就太好了。 有办法吗? 最佳答案 据我所知,没有
我正在尝试将 FXML 文件加载到我的 javafx 应用程序中作为我的根小部件,我使用带有 java 11.04 的 Windows 8.1 和带有 Eclipse 2019 IDE 的 javaf
我尝试加载 FXML 文件 MainView.fxml 就像在其他一些项目中所做的那样。但我得到“IllegalStateException:未设置位置。”但我很确定我传递了正确的位置。您还有其他想法
我们在场景构建器的帮助下创建了几个 JavaFX View 。它们的组件通过 FXMLLoader 注入(inject)到 Controller 类中,例如 TreeTableView。现在我想重写
我正在创建一个 ListView,能够双击每个项目并弹出一个窗口,其中包含由 FXML 文件构成的输入。 FXML 文件 itemStep 包含 fx:controller="controller.I
这个问题在这里已经有了答案: What is a NullPointerException, and how do I fix it? (12 个答案) 关闭 3 年前。 我是 java 和 mvc
我一直在为我的 JavaFX 学习做一个小应用程序。在应用程序中,我需要从主文件中单独获取 Controller ,所以我设计了这个: public class DiceObserver implem
我是一名优秀的程序员,十分优秀!