JavaFX——控制器don';看不到按钮或事件

JavaFX——控制器don';看不到按钮或事件,javafx,Javafx,为什么,当我点击“新建”按钮时,文本没有改变 主要类别: public class MainApp extends Application { @Override public void start(Stage primaryStage) throws IOException { BorderPane rootLayout = FXMLLoader.load(getClass().getResource("view/RootLayout.fxml")); AnchorPane

为什么,当我点击“新建”按钮时,文本没有改变

主要类别:

public class MainApp extends Application {

@Override
public void start(Stage primaryStage) throws IOException {
    BorderPane rootLayout = FXMLLoader.load(getClass().getResource("view/RootLayout.fxml"));

    AnchorPane code = FXMLLoader.load(getClass().getResource("view/DeskLayout.fxml"));
    rootLayout.setCenter(code);

    GridPane tool = FXMLLoader.load(getClass().getResource("view/ToolLayout.fxml"));
    rootLayout.setBottom(tool);

    primaryStage.setTitle("MyLittleIDE");
    primaryStage.setScene(new Scene(rootLayout));
    primaryStage.show();
}

public static void main(String[] args) {
    launch(args);
}
ToolLayoutController:

public class ToolLayoutController {
@FXML
private Button newButton;

@FXML
protected void handleNewProject(ActionEvent event) {
    newButton.setText("123");
}
ToolLaout.fxml

<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="30.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.mrchebik.view.ToolLayoutController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
  <Button fx:id="newButton" mnemonicParsing="false" onAction="#handleNewProject" prefHeight="30.0" prefWidth="150.0" text="New" GridPane.columnIndex="0" />
  <Button fx:id="compile" mnemonicParsing="false" prefHeight="51.0" prefWidth="150.0" text="Compile" GridPane.columnIndex="1" />
  <Button fx:id="run" mnemonicParsing="false" prefHeight="54.0" prefWidth="150.0" text="Run" GridPane.columnIndex="2" />
  <Button fx:id="save" mnemonicParsing="false" prefHeight="59.0" prefWidth="150.0" text="Save" GridPane.columnIndex="3" />
</children>
</GridPane>

RootLaout.fxml:

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<top>
  <MenuBar BorderPane.alignment="CENTER">
    <menus>
      <Menu mnemonicParsing="false" text="File">
        <items>
          <MenuItem mnemonicParsing="false" text="Close" />
        </items>
      </Menu>
      <Menu mnemonicParsing="false" text="Edit">
        <items>
          <MenuItem mnemonicParsing="false" text="Delete" />
        </items>
      </Menu>
      <Menu mnemonicParsing="false" text="Help">
        <items>
          <MenuItem mnemonicParsing="false" text="About" />
        </items>
      </Menu>
    </menus>
  </MenuBar>
</top>
</BorderPane>

DeskLayout.fxml

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<children>
  <SplitPane dividerPositions="0.8015075376884422" layoutX="196.0" layoutY="87.0" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
    <items>
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
           <children>
              <TextArea fx:id="code" layoutX="39.0" layoutY="-27.0" prefHeight="315.0" prefWidth="598.0" promptText="Code" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
           </children>
        </AnchorPane>
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
           <children>
              <TextArea fx:id="inOutPut" layoutX="-21.0" layoutY="-73.0" prefHeight="75.0" prefWidth="598.0" promptText="Input/Output" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
           </children>
        </AnchorPane>
    </items>
  </SplitPane>
</children>
</AnchorPane>


我还尝试使用javafx制作一个示例应用程序,并仅添加toollayout.fxml、controller和它。但是我不能在这个案例中这样做。

请将问题包括在FXML中,而不是发布到它的链接。另外,您的代码对我也适用。如果它对您不起作用,那么您选择不向我们显示的代码部分就有问题。创建一个项目,并将您的问题包含在内,这样您就可以保证您的问题中会显示任何错误。嗯,我可以给您一个zip文件中的项目绝对不会(这对任何其他用户来说究竟有何用处?)。请按要求做,你的问题包括一个。我更新一个帖子