Example usage for javafx.scene.control TableColumn setCellFactory

List of usage examples for javafx.scene.control TableColumn setCellFactory

Introduction

In this page you can find the example usage for javafx.scene.control TableColumn setCellFactory.

Prototype

public final void setCellFactory(Callback<TableColumn<S, T>, TableCell<S, T>> value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(450);//from ww w  .ja  v a  2s.co m
    stage.setHeight(550);

    table.setEditable(true);

    TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
    firstNameCol.setMinWidth(100);
    firstNameCol.setCellValueFactory(new PropertyValueFactory<>("firstName"));

    firstNameCol.setCellFactory(TextFieldTableCell.<Person>forTableColumn());
    firstNameCol.setOnEditCommit((CellEditEvent<Person, String> t) -> {
        ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setFirstName(t.getNewValue());
    });

    TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name");
    lastNameCol.setMinWidth(100);
    lastNameCol.setCellValueFactory(new PropertyValueFactory<>("lastName"));
    lastNameCol.setCellFactory(TextFieldTableCell.<Person>forTableColumn());
    lastNameCol.setOnEditCommit((CellEditEvent<Person, String> t) -> {
        ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setLastName(t.getNewValue());
    });
    table.setItems(data);
    table.getColumns().addAll(firstNameCol, lastNameCol);

    final VBox vbox = new VBox();
    vbox.setSpacing(5);
    vbox.setPadding(new Insets(10, 0, 0, 10));
    vbox.getChildren().addAll(table);

    ((Group) scene.getRoot()).getChildren().addAll(vbox);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Callback<TableColumn<Person, String>, TableCell<Person, String>> cellFactory = (
            TableColumn<Person, String> p) -> new EditingCell();

    Scene scene = new Scene(new Group());
    stage.setWidth(450);//from   w w  w . j a va  2 s  . co  m
    stage.setHeight(550);

    table.setEditable(true);

    TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
    firstNameCol.setMinWidth(100);
    firstNameCol.setCellValueFactory(new PropertyValueFactory<>("firstName"));
    firstNameCol.setCellFactory(cellFactory);

    firstNameCol.setOnEditCommit((CellEditEvent<Person, String> t) -> {
        ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setFirstName(t.getNewValue());
    });

    TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name");
    lastNameCol.setMinWidth(100);
    lastNameCol.setCellValueFactory(new PropertyValueFactory<>("lastName"));

    table.setItems(data);
    table.getColumns().addAll(firstNameCol, lastNameCol);

    final VBox vbox = new VBox();
    vbox.setSpacing(5);
    vbox.setPadding(new Insets(10, 0, 0, 10));
    vbox.getChildren().addAll(table);

    ((Group) scene.getRoot()).getChildren().addAll(vbox);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("java-buddy.blogspot.com");
    tableView.setEditable(true);/*www . j a  v  a2s  .c o  m*/
    Callback<TableColumn, TableCell> cellFactory = new Callback<TableColumn, TableCell>() {

        @Override
        public TableCell call(TableColumn p) {
            return new EditingCell();
        }
    };

    btnNew.setOnAction(btnNewHandler);

    //init table
    //Un-editable column of "id"
    TableColumn col_id = new TableColumn("ID");
    tableView.getColumns().add(col_id);
    col_id.setCellValueFactory(new PropertyValueFactory<Record, String>("id"));

    //Editable columns
    for (int i = 0; i < Day.length; i++) {
        TableColumn col = new TableColumn(Day[i]);
        col.setCellValueFactory(new PropertyValueFactory<Record, String>("value_" + String.valueOf(i)));
        tableView.getColumns().add(col);
        col.setCellFactory(cellFactory);
    }
    tableView.setItems(data);

    Group root = new Group();
    VBox vBox = new VBox();
    vBox.setSpacing(10);
    vBox.getChildren().addAll(btnNew, tableView);
    root.getChildren().add(vBox);
    primaryStage.setScene(new Scene(root, 500, 400));
    primaryStage.show();
}

From source file:com.ggvaidya.scinames.ui.BulkChangeEditorController.java

private void setupChangesTableView() {
    changesTableView.setEditable(true);//from w ww  .j a v  a 2  s. c o  m
    changesTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    changesTableView.getColumns().clear();

    TableColumn<PotentialChange, ChangeType> colChangeType = new TableColumn<>("Type");
    colChangeType.setCellFactory(ComboBoxTableCell.forTableColumn(new ChangeTypeStringConverter(),
            ChangeType.ADDITION, ChangeType.DELETION, ChangeType.RENAME, ChangeType.LUMP, ChangeType.SPLIT,
            ChangeType.ERROR));
    colChangeType.setCellValueFactory(new PropertyValueFactory<>("type"));
    colChangeType.setPrefWidth(100.0);
    colChangeType.setEditable(true);
    changesTableView.getColumns().add(colChangeType);

    TableColumn<PotentialChange, ObservableSet<Name>> colChangeFrom = new TableColumn<>("From");
    colChangeFrom.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter()));
    colChangeFrom.setCellValueFactory(new PropertyValueFactory<>("from"));
    colChangeFrom.setPrefWidth(200.0);
    colChangeFrom.setEditable(true);
    changesTableView.getColumns().add(colChangeFrom);

    TableColumn<PotentialChange, ObservableSet<Name>> colChangeTo = new TableColumn<>("To");
    colChangeTo.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter()));
    colChangeTo.setCellValueFactory(new PropertyValueFactory<>("to"));
    colChangeTo.setPrefWidth(200.0);
    colChangeTo.setEditable(true);
    changesTableView.getColumns().add(colChangeTo);

    TableColumn<PotentialChange, String> colChangeDataset = new TableColumn<>("Dataset");
    colChangeDataset.setCellValueFactory(new PropertyValueFactory<>("dataset"));
    colChangeDataset.setPrefWidth(100.0);
    changesTableView.getColumns().add(colChangeDataset);

    ChangeFilter cf = project.getChangeFilter();
    TableColumn<PotentialChange, String> colFiltered = new TableColumn<>("Eliminated by filter?");
    colFiltered.setCellValueFactory(
            (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper(
                    cf.test(features.getValue()) ? "Allowed" : "Eliminated"));
    changesTableView.getColumns().add(colFiltered);

    TableColumn<PotentialChange, String> colNote = new TableColumn<>("Note");
    colNote.setCellFactory(TextFieldTableCell.forTableColumn());
    colNote.setCellValueFactory(new PropertyValueFactory<>("note"));
    colNote.setPrefWidth(100.0);
    colNote.setEditable(true);
    changesTableView.getColumns().add(colNote);

    TableColumn<PotentialChange, String> colProperties = new TableColumn<>("Properties");
    colProperties.setCellValueFactory(
            (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper(
                    features.getValue().getProperties().entrySet().stream()
                            .map(entry -> entry.getKey() + ": " + entry.getValue()).sorted()
                            .collect(Collectors.joining("; "))));
    changesTableView.getColumns().add(colProperties);

    TableColumn<PotentialChange, String> colCitations = new TableColumn<>("Citations");
    colCitations.setCellValueFactory(
            (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper(
                    features.getValue().getCitationStream().map(citation -> citation.getCitation()).sorted()
                            .collect(Collectors.joining("; "))));
    changesTableView.getColumns().add(colCitations);

    TableColumn<PotentialChange, String> colGenera = new TableColumn<>("Genera");
    colGenera.setCellValueFactory(
            (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper(
                    String.join(", ", features.getValue().getAllNames().stream().map(n -> n.getGenus())
                            .distinct().sorted().collect(Collectors.toList()))));
    changesTableView.getColumns().add(colGenera);

    TableColumn<PotentialChange, String> colSpecificEpithet = new TableColumn<>("Specific epithet");
    colSpecificEpithet.setCellValueFactory(
            (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper(String
                    .join(", ", features.getValue().getAllNames().stream().map(n -> n.getSpecificEpithet())
                            .filter(s -> s != null).distinct().sorted().collect(Collectors.toList()))));
    changesTableView.getColumns().add(colSpecificEpithet);

    // TODO: if we can get an ObservableList over tp.getAllChanges(), then this table
    // will update dynamically as changes are made. Won't that be something.
    // Yes, we want to getAllChanges() so we can see which ones are filtered out.
    changesTableView.setItems(foundChanges);
    changesTableView.getSortOrder().add(colChangeType);
}

From source file:dpfmanager.shell.interfaces.gui.component.report.ReportsView.java

private void changeColumnTextColor(TableColumn column, Color color) {
    column.setCellFactory(new Callback<TableColumn, TableCell>() {
        public TableCell call(TableColumn param) {
            return new TableCell<ReportRow, String>() {
                @Override/*from ww w .j a va 2  s .  c  o  m*/
                public void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    if (!isEmpty()) {
                        this.setTextFill(color);
                        setText(item);
                    }
                }
            };
        }
    });
}

From source file:ninja.javafx.smartcsv.fx.SmartCSVController.java

/**
 * Adds a column with the given name to the tableview
 * @param header name of the column header
 * @param tableView the tableview/*from www . j a  va  2 s .  c om*/
 */
private void addColumn(final String header, TableView tableView) {
    TableColumn column = new TableColumn(header);
    column.setCellValueFactory(new ObservableMapValueFactory(header));
    column.setCellFactory(cellFactory);
    column.setEditable(true);
    column.setSortable(false);

    ContextMenu contextMenu = contextMenuForColumn(header);
    column.setContextMenu(contextMenu);

    column.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<CSVRow, CSVValue>>() {
        @Override
        public void handle(TableColumn.CellEditEvent<CSVRow, CSVValue> event) {
            event.getTableView().getItems().get(event.getTablePosition().getRow()).getColumns().get(header)
                    .setValue(event.getNewValue());
            runLater(() -> {
                currentCsvFile.setFileChanged(true);
            });
        }
    });

    tableView.getColumns().add(column);
}

From source file:com.exalttech.trex.ui.views.PacketTableView.java

/**
 * initialize packet table columns//from   ww  w .ja v  a2s.c  o m
 */
private void initializeTableColumn() {

    // add enable column
    streamPacketTableView.getColumns().add(createStaticTableColumn("", "enabledProperty", 30, true));

    // index column
    streamPacketTableView.getColumns().add(createStaticTableColumn("Index", "indexProperty", 50, false));

    streamPacketTableView.getColumns().add(createTableColumn("Name", "nameProperty", .17));
    streamPacketTableView.getColumns().add(createTableColumn("Packet Type", "packetTypeProperty", .25));
    TableColumn lengthColumn = createTableColumn("Length", "lengthProperty", .115);
    lengthColumn.setId("alignedColumn");
    streamPacketTableView.getColumns().add(lengthColumn);
    streamPacketTableView.getColumns().add(createTableColumn("Mode", "modeProperty", .175));
    TableColumn rateColumn = createTableColumn("Rate", "rateProperty", .115);
    rateColumn.setId("alignedColumn");
    streamPacketTableView.getColumns().add(rateColumn);

    TableColumn nextStreamCol = createTableColumn("Next Stream", "nextStreamProperty", .174);
    nextStreamCol.setCellFactory(new ImageCellFactory());
    streamPacketTableView.getColumns().add(nextStreamCol);

}

From source file:com.github.douglasjunior.simpleCSVEditor.FXMLController.java

private TableColumn<CSVRow, String> createColumn(int index) {
    TableColumn<CSVRow, String> col = new TableColumn<>((index + 1) + "");
    col.setSortable(false);/*from w w w  .  j a v  a  2  s  .co m*/
    col.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<CSVRow, String>, ObservableValue<String>>() {
                @Override
                public ObservableValue<String> call(TableColumn.CellDataFeatures<CSVRow, String> param) {
                    adjustColumns(param.getValue().getColumns());
                    return param.getValue().getColumns().get(index);
                }
            });
    col.setCellFactory(TextFieldTableCell.forTableColumn());
    col.setOnEditCommit(new EventHandler<CellEditEvent<CSVRow, String>>() {
        @Override
        public void handle(CellEditEvent<CSVRow, String> event) {
            adjustColumns(event.getRowValue().getColumns());
            event.getRowValue().getColumns().get(index).set(event.getNewValue());
            setNotSaved();
        }
    });
    col.setEditable(true);
    return col;
}

From source file:com.exalttech.trex.ui.views.PacketTableView.java

/**
 * Create and return static width table column
 *
 * @param title/*from   ww  w .j a v a  2 s . c o m*/
 * @param propertyName
 * @param width
 * @param hasCheckbox
 * @return
 */
private TableColumn createStaticTableColumn(String title, String propertyName, double width,
        boolean hasCheckbox) {
    TableColumn col = new TableColumn(title);
    col.setPrefWidth(width);
    col.setResizable(false);
    col.setEditable(false);
    col.setSortable(false);
    col.setCellValueFactory(new PropertyValueFactory<>(propertyName));
    if (hasCheckbox) {
        col.setEditable(true);
        col.setCellFactory(new CheckBoxTableViewCell(this));
    }
    return col;
}

From source file:com.github.drbookings.ui.controller.MainController.java

private void addOccupancyRateColumn() {
    final TableColumn<DateBean, Number> col = new TableColumn<>("OccupancyRate");
    col.setCellFactory(new OccupancyCellFactory());
    col.setCellValueFactory(new OccupancyCellValueFactory());
    tableView.getColumns().add(col);//  ww  w  . j  ava 2s. c  o  m
}