1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| package tablecheck;
import javafx.application.Application;
import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
setUserAgentStylesheet(STYLESHEET_CASPIAN);
final VBox root = new VBox();
root.getChildren().add(createTable(true, true));
root.getChildren().add(createTable(false, true));
root.getChildren().add(createTable(true, false));
root.getChildren().add(createTable(false, false));
final Scene scene = new Scene(root, 800, 800);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
private TableView createTable(final boolean columnEditable, final boolean tableEditable) {
final TableView<Boolean> tableView = new TableView();
final TableColumn<Boolean, Boolean> col1 = new TableColumn("Direct");
col1.setEditable(columnEditable);
col1.setCellFactory(CheckBoxTableCell.forTableColumn(col1));
final TableColumn<Boolean, Boolean> col2 = new TableColumn("Boolean");
col2.setEditable(columnEditable);
col2.setCellValueFactory(feature -> new SimpleBooleanProperty(feature.getValue()));
col2.setCellFactory(CheckBoxTableCell.forTableColumn(col1));
final TableColumn<Boolean, Boolean> col3 = new TableColumn("Boolean Wrapper");
col3.setEditable(columnEditable);
col3.setCellValueFactory(feature -> new ReadOnlyBooleanWrapper(feature.getValue()));
col3.setCellFactory(CheckBoxTableCell.forTableColumn(col1));
final TableColumn<Boolean, Boolean> col4 = new TableColumn("Boolean Read Only");
col4.setEditable(columnEditable);
col4.setCellValueFactory(feature -> new ReadOnlyBooleanWrapper(feature.getValue()).getReadOnlyProperty());
col4.setCellFactory(CheckBoxTableCell.forTableColumn(col1));
final TableColumn<Boolean, Boolean> col5 = new TableColumn("Object");
col5.setEditable(columnEditable);
col5.setCellValueFactory(feature -> new SimpleObjectProperty<>(feature.getValue()));
col5.setCellFactory(CheckBoxTableCell.forTableColumn(col1));
final TableColumn<Boolean, Boolean> col6 = new TableColumn("Object Wrapper");
col6.setEditable(columnEditable);
col6.setCellValueFactory(feature -> new ReadOnlyObjectWrapper<>(feature.getValue()));
col6.setCellFactory(CheckBoxTableCell.forTableColumn(col1));
final TableColumn<Boolean, Boolean> col7 = new TableColumn("Object Read Only");
col7.setEditable(columnEditable);
col7.setCellValueFactory(feature -> new ReadOnlyObjectWrapper<>(feature.getValue()).getReadOnlyProperty());
col7.setCellFactory(CheckBoxTableCell.forTableColumn(col1));
tableView.getColumns().setAll(col1, col2, col3, col4, col5, col6, col7);
// tableView.getItems().setAll(Boolean.TRUE, Boolean.FALSE, null);
tableView.getItems().addAll(Boolean.TRUE, Boolean.FALSE);
tableView.getItems().addAll(Boolean.TRUE, Boolean.FALSE);
tableView.getItems().addAll(Boolean.TRUE, Boolean.FALSE);
tableView.getItems().addAll(Boolean.TRUE, Boolean.FALSE);
tableView.getItems().addAll(Boolean.TRUE, Boolean.FALSE);
tableView.getItems().addAll(Boolean.TRUE, Boolean.FALSE);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.setEditable(tableEditable);
return tableView;
}
public static void main(String[] args) {
launch(args);
}
} |