3

i have Problems including the SpreadsheetView by ControlsFX into my FXML-file, is it even possible? Maybe someone could show some of his/her Code?

Thanks in advance!

1 Answers1

2

As you can read here, it seems ControlsFX and Scene Builder don't play well together (yet).

All I can managed to integrate was just the SpreadsheetView on a FXML file, more like a placeholder for the control, since we can't add a GridBase object.

<?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>

And then, in 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);
}
José Pereda
  • 44,311
  • 7
  • 104
  • 132