JavaFX处理程序不起作用

时间:2016-11-03 00:22:02

标签: java javafx

我的控制器有问题。当我点击按钮时,没有任何反应。 该方法将起作用:

@FXML
    public void handleNewProject() {
        code.setText("");
        inOutPut.setText("");
    }

它的按钮:

<Button mnemonicParsing="false" onMouseClicked="#handleNewProject" prefHeight="30.0" prefWidth="150.0" text="New" />

MainApp

public class MainApp extends Application {

private Stage primaryStage;
private BorderPane rootLayout;

@Override
public void start(Stage primaryStage) {
    this.primaryStage = primaryStage;
    this.primaryStage.setTitle("MyLittleIDE");

    initRootLayout();

    showDesk();
    showTool();
}

public void initRootLayout() {
    try {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource("view/RootLayout.fxml"));
        rootLayout = (BorderPane) loader.load();

        Scene scene = new Scene(rootLayout);
        primaryStage.setScene(scene);
        primaryStage.show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public void showDesk() {
    try {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource("view/DeskLayout.fxml"));
        AnchorPane personOverview = (AnchorPane) loader.load();

        rootLayout.setCenter(personOverview);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public void showTool() {
    try {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource("view/ToolLayout.fxml"));
        GridPane tool = (GridPane) loader.load();

        rootLayout.setBottom(tool);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

...

}

ToolLayout

public class ToolLayoutController {
    @FXML
    private TextArea code;
    @FXML
    private TextArea inOutPut;

    @FXML
    public void handleNewProject() {
        code.setText("");
        inOutPut.setText("");
    }
}

FXML&#39; S:

ToolLayout

<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 mnemonicParsing="false" onMouseClicked="#handleNewProject" prefHeight="30.0" prefWidth="150.0" text="New" />
      <Button mnemonicParsing="false" prefHeight="51.0" prefWidth="150.0" text="Compile" GridPane.columnIndex="1" />
      <Button mnemonicParsing="false" prefHeight="54.0" prefWidth="150.0" text="Run" GridPane.columnIndex="2" />
      <Button mnemonicParsing="false" prefHeight="59.0" prefWidth="150.0" text="Save" GridPane.columnIndex="3" />
   </children>
</GridPane>

DeskLayout

<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" fx:controller="ru.mrchebik.view.ToolLayoutController">
   <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>

和RootLayout有简单的MenuBar,没有设置

0 个答案:

没有答案