Java Code Examples for javafx.scene.control.TableView#setEditable()

The following examples show how to use javafx.scene.control.TableView#setEditable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatePickerCellDemo.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
public void start(Stage stage) throws Exception {
    TableView<Customer> tableView = new TableView<>(FXCollections.observableArrayList(Customer.createSample(555)));
    tableView.setEditable(true);

    TableColumn<Customer, String> username = new TableColumn<>("Username");
    username.setCellValueFactory(param -> param.getValue().usernameProperty());

    TableColumn<Customer, LocalDate> registered = new TableColumn<>("Registered");
    registered.setCellValueFactory(param -> param.getValue().registeredProperty());
    registered.setCellFactory(DatePickerTableCell.forTableColumn());
    registered.setPrefWidth(150);

    tableView.getColumns().addAll(username, registered);

    stage.setScene(new Scene(tableView, 800, 600));
    stage.show();
}
 
Example 2
Source File: AnimatedTableRow.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
private TableView<Person> createTable() {
    final TableView<Person> table = new TableView<Person>();
    table.setEditable(true);

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

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

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

    table.getColumns().addAll(Arrays.asList(firstNameCol, lastNameCol, emailCol));
    return table;
}
 
Example 3
Source File: GUI.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private TableView<Instance> createTable()
{
    final TableView<Instance> table = new TableView<>(FXCollections.observableList(model.getInstances()));
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    table.getSelectionModel().setCellSelectionEnabled(true);

    table.setEditable(true);

    TableColumn<Instance, String> col = new TableColumn<>(Messages.SystemColumn);
    col.setCellValueFactory(cell -> new SimpleStringProperty(cell.getValue().getName()));
    table.getColumns().add(col);

    int col_index = 0;
    for (Column column : model.getColumns())
    {
        final int the_col_index = col_index;
        col = new TableColumn<>(column.getName());
        col.setCellFactory(info -> new PACETableCell());
        col.setCellValueFactory(cell -> cell.getValue().getCell(the_col_index).getObservable());
        table.getColumns().add(col);

        if (column.isReadonly())
            col.setEditable(false);
        else
        {
            col.setOnEditCommit(event ->
            {
                event.getRowValue().getCell(the_col_index).setUserValue(event.getNewValue());
                final int row = event.getTablePosition().getRow();
                // Start to edit same column in next row
                if (row < table.getItems().size() - 1)
                    Platform.runLater(() ->  table.edit(row+1, event.getTableColumn()));
            });
        }

        ++col_index;
    }

    return table;
}
 
Example 4
Source File: ClientList.java    From Maus with GNU General Public License v3.0 4 votes vote down vote up
public TableView getClientList() {

        tableView = new TableView();
        tableView.setEditable(true);
        tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
        tableView.getStylesheets().add(getClass().getResource("/css/global.css").toExternalForm());

        TableColumn<String, String> onlineStatus = new TableColumn<>("Status");
        onlineStatus.setMaxWidth(70);
        onlineStatus.setResizable(false);
        onlineStatus.setCellValueFactory(
                new PropertyValueFactory<>("onlineStatus"));

        TableColumn<ClientObject, String> nickName = new TableColumn<>("Nickname");
        nickName.setMinWidth(150);
        nickName.setMaxWidth(200);
        nickName.setResizable(false);
        nickName.setCellValueFactory(new PropertyValueFactory<>("nickName"));
        nickName.setCellFactory(TextFieldTableCell.forTableColumn());
        nickName.setOnEditCommit(
                t -> t.getTableView().getItems().get(
                        t.getTablePosition().getRow()).setNickName(t.getNewValue())
        );

        TableColumn<ClientObject, String> IP = new TableColumn<>("IP");
        IP.setMinWidth(600);
        IP.setResizable(false);
        IP.setCellValueFactory(new PropertyValueFactory<>("IP"));
        IP.setCellFactory(col -> {
            final TableCell<ClientObject, String> cell = new TableCell<>();
            cell.textProperty().bind(cell.itemProperty());
            cell.setOnMouseClicked(event -> {
                if (event.getButton().equals(MouseButton.SECONDARY) && cell.getTableView().getSelectionModel().getSelectedItem() != null && cell.getTableView().getSelectionModel().getSelectedItem().getClient().isConnected()) {
                    IPContextMenu.getIPContextMenu(cell, event);
                }
            });
            return cell;
        });
        ObservableList<ClientObject> list = FXCollections.observableArrayList();
        list.addAll(CONNECTIONS.values());
        tableView.setItems(list);
        tableView.getColumns().addAll(onlineStatus, nickName, IP);

        return tableView;
    }