Example usage for javafx.scene.control TableView setPrefWidth

List of usage examples for javafx.scene.control TableView setPrefWidth

Introduction

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

Prototype

public final void setPrefWidth(double value) 

Source Link

Usage

From source file:Main.java

private TableView<Person> createEmployeeTableView(ObservableList<Person> teamMembers) {
    final TableView<Person> employeeTableView = new TableView<>();
    employeeTableView.setPrefWidth(300);

    employeeTableView.setItems(teamMembers);

    TableColumn<Person, String> aliasNameCol = new TableColumn<>("Alias");
    TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
    TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name");

    aliasNameCol.setEditable(true);//  www  .jav  a 2 s  .c  om

    aliasNameCol.setPrefWidth(employeeTableView.getPrefWidth() / 3);
    firstNameCol.setPrefWidth(employeeTableView.getPrefWidth() / 3);
    lastNameCol.setPrefWidth(employeeTableView.getPrefWidth() / 3);

    aliasNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("aliasName"));
    firstNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
    lastNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));

    employeeTableView.getColumns().setAll(aliasNameCol, firstNameCol, lastNameCol);

    return employeeTableView;
}