All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datafx.samples.ActionTableCellDemo Maven / Gradle / Ivy

The newest version!
package org.datafx.samples;

import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.datafx.control.cell.ActionTableCell;

public class ActionTableCellDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    public class Person {

        private String name;

        Person(String name) {
            this.name = name;
        }

        private String getName() {
            return name;
        }
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        ObservableList data = FXCollections.observableArrayList(new Person("Hendrik"), new Person("Jonathan"), new Person("Johan"));

        TableView table = new TableView<>(data);

        TableColumn col1 = new TableColumn("Names");
        col1.setCellValueFactory((e) -> new SimpleStringProperty(e.getValue().getName()));

        TableColumn col2 = new TableColumn("Delete");
        col2.setCellFactory((e) -> ActionTableCell.createWithButton((s) -> data.remove(s), "X"));

        table.getColumns().addAll(col1, col2);

        primaryStage.setScene(new Scene(new StackPane(table)));
        primaryStage.show();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy