如何将 ControlsFx SpreadsheetView 导入我的 FXML 文件?

How to import the ControlsFx SpreadsheetView into my FXML-File?

我在将 ControlsFX 的 SpreadsheetView 包含到我的 FXML 文件中时遇到问题,这甚至可能吗?也许有人可以展示一些 his/her 代码?

提前致谢!

如您所见here,ControlsFX 和 Scene Builder 似乎不能很好地协同工作(目前)。

我所能集成的只是 FXML 文件上的 SpreadsheetView,更像是控件的占位符,因为我们无法添加 GridBase 对象。

<?xml version="1.0" encoding="UTF-8"?>

<?import org.controlsfx.control.*?>
<?import org.controlsfx.control.spreadsheet.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>


<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
   <children>
      <SpreadsheetView fx:id="spreadsheet" editable="true" showRowHeader="true" showColumnHeader="true" prefHeight="300.0" prefWidth="400.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"/>
   </children>
</AnchorPane>

然后,在Controller中:

@FXML private SpreadsheetView spreadsheet;
/**
 * Initializes the controller class.
 * @param url
 * @param rb
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    int rowCount = 5;
    int columnCount = 3;
    GridBase grid = new GridBase(rowCount, columnCount);

    ObservableList<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
    for (int row = 0; row < grid.getRowCount(); ++row) {
        final ObservableList<SpreadsheetCell> list = FXCollections.observableArrayList();
        for (int column = 0; column < grid.getColumnCount(); ++column) {
            list.add(SpreadsheetCellType.STRING.createCell(row, column, 1, 1,"value"));
        }
        rows.add(list);
    }
    grid.setRows(rows);
    spreadsheet.setGrid(grid);
}