Example usage for javafx.scene.control TableColumn setCellValueFactory

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

Introduction

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

Prototype

public final void setCellValueFactory(Callback<CellDataFeatures<S, T>, ObservableValue<T>> value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Table View Sample");
    stage.setWidth(300);/* w  w w .j  a va 2s  .  c  o m*/
    stage.setHeight(500);

    final Label label = new Label("Student IDs");
    label.setFont(new Font("Arial", 20));

    TableColumn<Map, String> firstDataColumn = new TableColumn<>("Class A");
    TableColumn<Map, String> secondDataColumn = new TableColumn<>("Class B");

    firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey));
    firstDataColumn.setMinWidth(130);
    secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey));
    secondDataColumn.setMinWidth(130);

    TableView tableView = new TableView<>(generateDataInMap());

    tableView.setEditable(true);
    tableView.getSelectionModel().setCellSelectionEnabled(true);
    tableView.getColumns().setAll(firstDataColumn, secondDataColumn);
    Callback<TableColumn<Map, String>, TableCell<Map, String>> cellFactoryForMap = (
            TableColumn<Map, String> p) -> new TextFieldTableCell(new StringConverter() {
                @Override
                public String toString(Object t) {
                    return t.toString();
                }

                @Override
                public Object fromString(String string) {
                    return string;
                }
            });
    firstDataColumn.setCellFactory(cellFactoryForMap);
    secondDataColumn.setCellFactory(cellFactoryForMap);

    final VBox vbox = new VBox();

    vbox.setSpacing(5);
    vbox.setPadding(new Insets(10, 0, 0, 10));
    vbox.getChildren().addAll(label, tableView);

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

    stage.setScene(scene);

    stage.show();
}

From source file:com.bdb.weather.display.summary.RainSummary.java

@SuppressWarnings("LeakingThisInConstructor")
public RainSummary(SummaryInterval interval, SummarySupporter supporter) {
    this.setPrefSize(500, 300);
    this.interval = interval;
    this.supporter = supporter;
    dataTable = new TableView();
    Node component = createChartElements();

    TableColumn<SummaryRecord, String> col = new TableColumn<>("Date");
    col.setCellValueFactory(
            (rec) -> new ReadOnlyStringWrapper(DisplayConstants.formatDate(rec.getValue().getDate())));
    dataTable.getColumns().add(col);/*from   w  w w  .  j a v a 2 s . c  om*/

    TableColumn<SummaryRecord, Depth> rainfallColumn = new TableColumn<>("Rainfall");
    rainfallColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getTotalRainfall()));
    dataTable.getColumns().add(rainfallColumn);

    TableColumn<SummaryRecord, Depth> etColumn = new TableColumn<>("ET");
    etColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getTotalET()));
    dataTable.getColumns().add(etColumn);

    this.setTabContents(component, dataTable);
}

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);//ww w.java2 s  . c  o 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:com.bdb.weather.display.summary.WindSummary.java

/**
 * Create the table./*from   w ww. j  av a  2 s  .  c  o  m*/
 * 
 * @return The JavaFX Node
 */
private Node createTable() {
    dataTable = new TableView();

    TableColumn<SummaryRecord, String> col = new TableColumn<>("Date");
    col.setCellValueFactory(
            (rec) -> new ReadOnlyStringWrapper(DisplayConstants.formatDate(rec.getValue().getDate())));
    dataTable.getColumns().add(col);

    TableColumn<SummaryRecord, Speed> avgWindColumn = new TableColumn<>("Avg Wind");
    avgWindColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getAvgWindSpeed()));
    dataTable.getColumns().add(avgWindColumn);

    TableColumn<SummaryRecord, Depth> maxWindColumn = new TableColumn<>("Max Wind");
    maxWindColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getMaxWindSpeed()));
    dataTable.getColumns().add(maxWindColumn);

    TableColumn<SummaryRecord, Depth> maxGustColumn = new TableColumn<>("Max Wind");
    maxGustColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getMaxWindGust()));
    dataTable.getColumns().add(maxGustColumn);

    return dataTable;
}

From source file:com.bdb.weather.display.windrose.WindRosePane.java

/**
 * Constructor./*from   www.  j a v  a  2 s.c om*/
 */
public WindRosePane() {
    this.setPrefSize(300, 300);
    ChartFactory.getChartTheme().apply(chart);
    chartViewer.setMinHeight(10);
    chartViewer.setMinWidth(10);
    chartViewer.setPrefSize(300, 300);

    dataTable = new TableView();

    FlowPane summaryPanel = new FlowPane();

    summaryPanel.getChildren().add(new LabeledFieldPane<>("Date:", timeField));
    timeField.setEditable(false);
    summaryPanel.getChildren().add(new LabeledFieldPane<>("% Winds are calm:", calmField));
    calmField.setEditable(false);

    summaryPanel.getChildren().add(new Label("Speeds are in " + Speed.getDefaultUnit()));

    BorderPane p = new BorderPane();

    p.setCenter(dataTable);
    p.setTop(summaryPanel);
    this.setTabContents(chartViewer, p);

    TableColumn<WindSlice, String> headingColumn = new TableColumn<>("Heading");
    headingColumn.setCellValueFactory((rec) -> new ReadOnlyStringWrapper(
            Heading.headingForSlice(rec.getValue().getHeadingIndex(), 16).getCompassLabel()));
    dataTable.getColumns().add(headingColumn);

    TableColumn<WindSlice, String> percentOfWindColumn = new TableColumn<>("% of Wind");
    percentOfWindColumn.setCellValueFactory(
            (rec) -> new ReadOnlyStringWrapper(String.format("%.1f", rec.getValue().getPercentageOfWind())));
    dataTable.getColumns().add(percentOfWindColumn);

    TableColumn<WindSlice, Speed> avgSpeedColumn = new TableColumn<>("Avg Speed");
    avgSpeedColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper<>(rec.getValue().getAvgSpeed()));
    dataTable.getColumns().add(avgSpeedColumn);

    TableColumn<WindSlice, Speed> maxSpeedColumn = new TableColumn<>("Max Speed");
    maxSpeedColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper<>(rec.getValue().getMaxSpeed()));
    dataTable.getColumns().add(maxSpeedColumn);

}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("java-buddy.blogspot.com");
    tableView.setEditable(true);/*from www . j  av a2 s  .  co 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:org.pdfsam.ui.selection.multiple.LoadingStatusColumn.java

public TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus> getTableColumn() {
    TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus> tableColumn = new TableColumn<>(
            getColumnTitle());/*from   ww  w.jav a2 s. c  o  m*/
    tableColumn.setCellFactory(cellFactory());
    tableColumn.setCellValueFactory(cellValueFactory());
    tableColumn.setSortable(false);
    tableColumn.setMaxWidth(22);
    tableColumn.setMinWidth(22);
    return tableColumn;
}

From source file:com.rcs.shoe.shop.fx.controller.ui.ProductsController.java

public void initialize(URL url, ResourceBundle rb) {
    TableColumn firstCol = (TableColumn) productsTable.getColumns().get(0);
    PropertyValueFactory p1 = new PropertyValueFactory<>("productNum");
    firstCol.setCellValueFactory(p1);

    TableColumn secCol = (TableColumn) productsTable.getColumns().get(1);
    PropertyValueFactory p2 = new PropertyValueFactory<>("productCode");
    secCol.setCellValueFactory(p2);/*  w ww .  java2 s .c o  m*/

    TableColumn thirdCol = (TableColumn) productsTable.getColumns().get(2);
    PropertyValueFactory p3 = new PropertyValueFactory<>("quantity");
    thirdCol.setCellValueFactory(p3);

    productsTable.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
        if (newSelection != null && newSelection instanceof V_Products) {
            V_Products selectedProd = (V_Products) newSelection;
            selProductCode.textProperty().setValue(selectedProd.getProductCode());
            selProductNum.textProperty().setValue(selectedProd.getProductNum().toString());
        }
    });

    ObservableList<V_Products> prod = FXCollections.observableArrayList(productService.findAll());
    products = new FilteredList<>(prod, p -> true);
    productsTable.setItems(products);

    initVisibility();
}

From source file:com.bdb.weather.display.windrose.WindRosePane.java

/**
 * Initialize the component.//  w w  w. j a  v a  2s . c  o m
 * 
 * @param bins The speed bins
 */
private void init(List<SpeedBin> bins) {
    if (initialized)
        return;

    initialized = true;

    int binNumber = 0;
    for (SpeedBin bin : bins) {
        TableColumn<WindSlice, String> column = new TableColumn<>(bin.speedString());
        column.setUserData(binNumber++);
        column.setCellValueFactory((rec) -> new ReadOnlyStringWrapper(String.format("%.1f",
                rec.getValue().speedBinPercentage((int) rec.getTableColumn().getUserData()))));
        dataTable.getColumns().add(column);
    }
}

From source file:org.pdfsam.ui.selection.multiple.LoadingColumn.java

@Override
public TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus> getTableColumn() {
    TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus> tableColumn = new TableColumn<>(
            getColumnTitle());/*from www . j  a va2 s.  c  o m*/
    tableColumn.setCellFactory(cellFactory());
    tableColumn.setCellValueFactory(cellValueFactory());
    tableColumn.setComparator(null);
    tableColumn.setSortable(false);
    tableColumn.setMaxWidth(26);
    tableColumn.setMinWidth(26);
    return tableColumn;
}