Feras Odeh Feras Odeh - 1 year ago 709
Java Question

Set Row Height in JavaFX TableView

How can I set row Height in JavaFX table View? I tried to increase it by using css but this didn't work:

line-height: 50px;

Is there any other way to solve this?

Answer Source

You can use

.table-row-cell {
    -fx-cell-size: 50px;

The .table-row-cell is the class assigned to the table rows, as stated in capian.css, available at jfxrt.jar (com/sun/javafx/scene/control/skin/caspian/caspian.css):

Each row in the table is a table-row-cell. Inside a table-row-cell is any number of table-cell.

And -fx-cell-size, in this case, is the row height (actually, each cell height), as confirmed at Oracle's JavaFX CSS Reference Guide

-fx-cell-size: The cell size. For vertical ListView or a TreeView or TableView this is the height, for a horizontal ListView this is the width.

I tried the solution above on the following example:

PetsTable: (Note the use of scene.getStylesheets().add("styles/styles.css");, defining the css file to be employed)

import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;

public class PetsTable extends Application {

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void start(Stage stage) {
        Scene scene = new Scene(new Group());

        ObservableList<Pet> data = FXCollections.observableArrayList(new Pet("Kitty", "Susan"), 
                new Pet("Ploft", "Jackob"));
        TableView<Pet> table = new TableView<Pet>();

        TableColumn name = new TableColumn("Name");
        name.setCellValueFactory(new PropertyValueFactory<Pet, String>("name"));

        TableColumn owner = new TableColumn("Owner");
        owner.setCellValueFactory(new PropertyValueFactory<Pet, String>("owner"));

        table.getColumns().addAll(name, owner);

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

        /********* Setting the css style file *******/


    public static void main(String[] args) {

    public static class Pet {

        private final SimpleStringProperty name;
        private final SimpleStringProperty owner;

        private Pet(String name, String owner) {
            this.name = new SimpleStringProperty(name);
            this.owner = new SimpleStringProperty(owner);

        public String getName() {
            return name.get();

        public String getOwner() {
            return owner.get();


.table-row-cell {
    -fx-cell-size: 50px;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download