Example usage for javafx.scene.control TableColumn TableColumn

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

Introduction

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

Prototype

public TableColumn(String text) 

Source Link

Document

Creates a TableColumn with the text set to the provided string, with default cell factory, comparator, and onEditCommit implementation.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    TableView table = new TableView();
    table.setEditable(true);//w  w w.  ja v a2  s. c  o  m

    TableColumn firstNameCol = new TableColumn("First Name");
    TableColumn lastNameCol = new TableColumn("Last Name");
    TableColumn emailCol = new TableColumn("Email");

    table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
    emailCol.setVisible(false);

    StackPane root = new StackPane();
    root.getChildren().add(table);
    primaryStage.setScene(new Scene(root, 200, 250));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    TableView table = new TableView();
    table.setEditable(true);//from  w  w w  .  j av a  2s . c  om

    TableColumn firstNameCol = new TableColumn("First Name");
    TableColumn lastNameCol = new TableColumn("Last Name");
    TableColumn addressCol = new TableColumn("Email");

    table.getColumns().addAll(firstNameCol, lastNameCol, addressCol);

    TableColumn cityCol = new TableColumn("City");
    TableColumn stateCol = new TableColumn("State");

    addressCol.getColumns().addAll(cityCol, stateCol);

    StackPane root = new StackPane();
    root.getChildren().add(table);
    primaryStage.setScene(new Scene(root, 200, 250));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(450);/*from   www  . j  ava  2 s  .  com*/
    stage.setHeight(550);

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

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

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

    firstNameCol.setSortType(TableColumn.SortType.DESCENDING);
    lastNameCol.setSortable(false);

    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) {
    Scene scene = new Scene(new Group());
    stage.setWidth(450);//from w  w w. j  a  v a2 s  . c  o  m
    stage.setHeight(550);

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

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

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

    final Button addButton = new Button("Add");
    addButton.setOnAction((ActionEvent e) -> {
        data.add(new Person("Z", "X"));
    });

    hb.getChildren().addAll(addButton);
    hb.setSpacing(3);

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

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

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

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(450);//  ww w  .  j  a  v a  2s  .  c om
    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) {
    Scene scene = new Scene(new Group());
    stage.setWidth(400);//from   w w  w .j  av a2 s. c om
    stage.setHeight(550);

    table.setEditable(true);

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

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

    TableColumn emailCol = new TableColumn("Email");
    emailCol.setMinWidth(200);
    emailCol.setCellValueFactory(new PropertyValueFactory<Person, String>("email"));

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

    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) {
    Scene scene = new Scene(new Group());
    stage.setWidth(400);//from w  ww  . ja v  a2 s.c  om
    stage.setHeight(550);

    table.setEditable(true);

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

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

    TableColumn emailCol = new TableColumn("Email");
    emailCol.setMinWidth(200);
    emailCol.setCellValueFactory(new PropertyValueFactory<Person, String>("email"));

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

    final Button addButton = new Button("Add");
    addButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            data.add(new Person("new", "new", "new"));
        }
    });

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

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

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

From source file:br.com.ajaio.midas.desktop.controller.ContaCrudFXMLController.java

/**
 * Initializes the controller class.//  w  ww.  j  av a2s .c o m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    TableColumn nomeBancoCol = new TableColumn("Banco");
    nomeBancoCol.setMinWidth(200);
    nomeBancoCol.setCellValueFactory(new PropertyValueFactory<Conta, String>("nomeBanco"));

    TableColumn agenciaCol = new TableColumn("Agncia");
    agenciaCol.setMinWidth(200);
    agenciaCol.setCellValueFactory(new PropertyValueFactory<Conta, String>("agencia"));

    TableColumn contaCol = new TableColumn("Conta");
    contaCol.setMinWidth(200);
    contaCol.setCellValueFactory(new PropertyValueFactory<Conta, String>("conta"));

    TableColumn saldoCol = new TableColumn("Saldo Atual");
    saldoCol.setMinWidth(200);
    saldoCol.setCellValueFactory(new PropertyValueFactory<Conta, String>("saldoAtual"));

    TableColumn editar = new TableColumn("Editar");

    TableColumn apagar = new TableColumn("Apagar");

    tbContas.getColumns().addAll(nomeBancoCol, agenciaCol, contaCol, saldoCol, editar, apagar);

    context = new ClassPathXmlApplicationContext("application-context.xml");
}

From source file:br.com.ajaio.midas.desktop.controller.BancoCrudFXMLController.java

/**
 * Initializes the controller class./*from   ww  w  .j av a2 s. c  om*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    TableColumn nomeCol = new TableColumn("Nome Banco");
    nomeCol.setMinWidth(200);
    nomeCol.setCellValueFactory(new PropertyValueFactory<Banco, String>("nome"));

    TableColumn numeroCol = new TableColumn("Nmero Banco");
    numeroCol.setMinWidth(150);
    numeroCol.setCellValueFactory(new PropertyValueFactory<Banco, String>("numeroBanco"));

    TableColumn editar = new TableColumn("Editar");

    TableColumn apagar = new TableColumn("Apagar");

    tbBancos.getColumns().addAll(nomeCol, numeroCol, editar, apagar);

    context = new ClassPathXmlApplicationContext("application-context.xml");
}

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 ww. j a  va  2s. co 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();
}