Example usage for javafx.scene.control TableView getPrefWidth

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

Introduction

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

Prototype

public final double getPrefWidth() 

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);/*  w  w w.  j  ava2  s  .  c o  m*/

    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;
}