Javafx 使用FXML和控制器类将复选框添加到tableview

Javafx 使用FXML和控制器类将复选框添加到tableview,javafx,tableview,fxml,Javafx,Tableview,Fxml,所以我只是想给我的程序添加一个复选框。唯一的问题是,我不知道如何使用FXML和普通javaFX来实现这一点。你们能帮帮我吗 这是我的主要课程 package sample; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.image.Image; impo

所以我只是想给我的程序添加一个复选框。唯一的问题是,我不知道如何使用FXML和普通javaFX来实现这一点。你们能帮帮我吗

这是我的主要课程

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        try {
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(Main.class.getResource("/sample/sample.fxml"));
            AnchorPane rootLayout = loader.load();

            Scene scene = new Scene(rootLayout);
            //rootLayout.prefWidthProperty().bind(scene.widthProperty()); not needed
            //rootLayout.prefHeightProperty().bind(scene.heightProperty());in these scenario
            primaryStage.setScene(scene);
            primaryStage.getIcons().add(new Image("/sample/img/Java.png"));
            primaryStage.setTitle("Tool-Downloader");
            primaryStage.show();
            primaryStage.setResizable(false);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        launch(args);
    }
}
我的控制器:

package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

import static java.util.ServiceLoader.load;

public class Controller {

    @FXML
    private void downloadButton(ActionEvent event){

        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("grievous.fxml"));
            Parent root1 = (Parent) fxmlLoader.load();
            Stage stage = new Stage();
            stage.setScene(new Scene(root1));
            stage.show();
            stage.setResizable(false);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    @FXML
    private void close(ActionEvent onClick){
        ((Stage)(((javafx.scene.control.Button)onClick.getSource()).getScene().getWindow())).close();
    }

    @FXML
    public void selection(){

    }
    }
我的FXML文件:

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.String?>
<?import javafx.scene.control.cell.*?>
<?import javafx.collections.*?>
<?import javafx.collections.FXCollections?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.CheckBox?>
<?import sample.Programs?>
<?import sample.Selection?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.scene.image.Image?>
<AnchorPane maxHeight="-Infinity" maxWidth="1000" minHeight="650" minWidth="900" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" style="-fx-background-color: white" fx:controller="sample.Controller"
            stylesheets="/sample/style1.css">
    <HBox alignment="CENTER_LEFT" layoutX="6.0" layoutY="14.0" spacing="52.0" AnchorPane.leftAnchor="0.0"
              AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" styleClass="background">
            <padding>
                <Insets left="10.0" right="3.0" top="5.0"/>
            </padding>
            <ComboBox fx:id="versionCombo" prefWidth="150.0" promptText="Choose OS" styleClass="combox2">
                <items>
                    <FXCollections fx:factory="observableArrayList">
                        <String fx:value="Windows"/>
                        <String fx:value="Mac OS X"/>
                        <String fx:value="Ubuntu"/>
                    </FXCollections>
                </items>
            </ComboBox>
            <Button onAction="#downloadButton" minWidth="80.0" mnemonicParsing="false" text="Download" styleClass="button1"/>
        <HBox>
            <padding>
                <Insets left="550.0" right="0.0" top="0.0"/>
            </padding>
                <Button onAction="#close" minWidth="80.0" mnemonicParsing="false" text="close" styleClass="close"/>
        </HBox>
    </HBox>
        <TableView fx:id="tableView" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="2.0" AnchorPane.rightAnchor="2.0" AnchorPane.topAnchor="40.0" styleClass="table-view">
            <columns>
                <TableColumn fx:id="selection" prefWidth="100.0" maxWidth="100.0" minWidth="100" text="Selection" styleClass="table1" >
                    <cellValueFactory>

                    </cellValueFactory>
                </TableColumn>
                <TableColumn fx:id="date" prefWidth="652" maxWidth="652" minWidth="652" text="Program" styleClass="table2">
                    <cellValueFactory>
                        <PropertyValueFactory property="programs"/>
                    </cellValueFactory>
                </TableColumn>
                <TableColumn fx:id="release" prefWidth="150" maxWidth="150" minWidth="150" text="Date" styleClass="table3">
                    <cellValueFactory>
                        <PropertyValueFactory property="date"/>
                    </cellValueFactory>
                </TableColumn>
                <TableColumn fx:id="opsystem" prefWidth="100" minWidth="100" maxWidth="100" text="OS" styleClass="table4">
                    <cellValueFactory>
                        <PropertyValueFactory property="operatingSystem"/>
                        <PropertyValueFactory property="java"/>
                    </cellValueFactory>
                </TableColumn>
            </columns>
            <items>
                <FXCollections fx:factory="observableArrayList">
                    <Programs programs="Google Chrome is one of the most popular webbrowsers to date. It has many addons and features." date="06.07.2017" operatingSystem="Windows"/>

                </FXCollections>
            </items>
        </TableView>
</AnchorPane>
我已经为此搜索了很长一段时间,但什么也找不到

package sample;

import javafx.beans.property.SimpleStringProperty;

public class Programs {
    private final SimpleStringProperty firstName = new SimpleStringProperty("");
    private final SimpleStringProperty lastName = new SimpleStringProperty("");
    private final SimpleStringProperty email = new SimpleStringProperty("");

    public Programs() {
        this("", "", "");
    }

    public Programs(String firstName, String lastName, String email) {
        setPrograms(firstName);
        setDate(lastName);
        setOperatingSystem(email);
    }

    public String getPrograms() {
        return firstName.get();
    }

    public void setPrograms(String fName) {
        firstName.set(fName);
    }

    public String getDate() {
        return lastName.get();
    }

    public void setDate(String fName) {
        lastName.set(fName);
    }

    public String getOperatingSystem(){
        return email.get();
    }

    public void setOperatingSystem(String fName){
        email.set(fName);
    }

}