JavaFX选项卡窗格未显示



我正试图使用一个应用程序的FXML应用程序创建一个简单的UI,该应用程序最终会将文本文件发送到另一个要在那里使用的应用程序。我对这个选项卡窗格中的第一个选项卡的目标是允许用户输入自己的组名,并将其添加到他们输入的所有组名的列表中。我希望用户在textField中键入组名,然后单击添加按钮,将组名移动到textArea,然后转到新行。我想我已经得到了正确的操作处理程序,但我不能测试它,因为当我运行程序时,什么都不会显示!如有任何帮助,我们将不胜感激。

Java代码:

package pipeline.ui;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
 *
 * @author Pat
 */
public class PipelineUI extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("PipelineUI.fxml"));
        Scene scene = new Scene(root, 1000, 1000);
        stage.setTitle("Pipeline Welcome");
        stage.setScene(scene);
        stage.show();
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}

控制器代码:

package pipeline.ui;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
/**
 *
 * @author Pat
 */
public class PipelineUIController implements Initializable {
    private Label label;
    @FXML
    private Tab groupsTab;
    @FXML
    private Button addGroup;
    @FXML
    private Button removeGroup;
    @FXML
    private Button proceedButton1;
    @FXML
    public TextArea groupsList;
    @FXML
    private TextField groupName;
    private static final String newline = "n";
    public void handleButtonAction(ActionEvent event) {
        if (groupName.getText() != "")
        {
            String name = groupName.getText();
            groupsList.appendText(name);
            groupsList.appendText(newline);
        }
    }
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }    
}

FXML代码:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"     prefHeight="1000.0" prefWidth="1000.0" tabClosingPolicy="UNAVAILABLE"     xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8"     fx:controller="pipeline.ui.PipelineUIController">
  <tabs>
    <Tab fx:id="groupsTab" text="Experimental Groups">
      <content>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
               <children>
                  <Button fx:id="addGroup" layoutX="253.0" layoutY="100.0"     mnemonicParsing="false" onMouseClicked="handleButtonAction"  text="Add Group &gt;&gt;" />
                  <Button fx:id="removeGroup" layoutX="242.0" layoutY="173.0"     mnemonicParsing="false" text="&lt;&lt; Remove Group" />
                  <Button fx:id="proceedButton1" layoutX="534.0" layoutY="332.0"     mnemonicParsing="false" text="OK" />
                  <TextArea fx:id="groupsList" layoutX="367.0" layoutY="86.0" prefHeight="200.0"     prefWidth="200.0" />
                  <TextField fx:id="groupName" layoutX="77.0" layoutY="100.0" />
                  <Text layoutX="77.0" layoutY="82.0" strokeType="OUTSIDE" strokeWidth="0.0"     text="Add experimental groups to be examined:" />
               </children></AnchorPane>
      </content>
    </Tab>
    <Tab text="Untitled Tab 2">
      <content>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
      </content>
    </Tab>
  </tabs>
</TabPane>

不确定是否所有这些都是必要的,但如果有人能在这里帮助我,我真的很感激。谢谢!

这甚至不会为我运行,因为您的FXML中有错误。addGroup按钮的处理程序应该是"#handleButtonAction"("#"表示它属于控制器,是一个脚本)。

此外,由于handler方法将ActionEvent作为其参数,因此它应该是

onAction="#handleButtonAction"

(不是onMouseClicked)。

最新更新