Unable to select row in TableView depending on stage height

Kroiß, Florian Florian.Kroiss at vector.com
Tue Dec 12 14:28:24 UTC 2023


Hi everyone,

there seems to be a bug where, depending on the current stage height, it is not possible to select a row in a TableView by clicking on it.
There is an existing bug (https://bugs.openjdk.org/browse/JDK-8133697) which attributes this problem to maximizing the window, but I think it is more generally related to the stage height itself.
Using the following code, I'm able to consistently reproduce the problem with JavaFX 21.0.1 on two different Windows 11 machines:

package bug_report;

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.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Table extends Application {
    VBox root = new VBox();

    private final TableView< Entry > table = new TableView<>();

    private final ObservableList< Entry > data = FXCollections.observableArrayList(new Entry("A"), new Entry("B"),
        new Entry("C"), new Entry("D"));

    public static void main(final String[] args) {
        launch(args);
    }

    @Override
    public void start(final Stage stage) {
        Scene scene = new Scene(new Group());
        final double weight = scene.getWidth();
        final double height = scene.getHeight();
        stage.setTitle("Table View Sample");
        stage.setWidth(1000);
        stage.setHeight(1038);
        table.setEditable(true);

        final TableColumn< Entry, String > valueCol = new TableColumn<>("Value");
        valueCol.setMinWidth(1000);
        valueCol.setCellValueFactory(new PropertyValueFactory< Entry, String >("value"));

        table.setItems(data);
        table.getColumns().add(valueCol);
        root.getChildren().addAll(table);

        final Button plus = new Button("+");
        plus.setOnMouseClicked(evt -> {
            stage.setHeight(stage.getHeight() + 1);
        });
        final Button minus = new Button("-");
        minus.setOnMouseClicked(evt -> {
            stage.setHeight(stage.getHeight() - 1);
        });
        root.getChildren().addAll(plus, minus);

        stage.heightProperty().addListener((obs, oldV, newV) -> {
            System.out.println("New height is: " + newV);
        });

        scene = new Scene(root, weight, height, true);
        stage.setScene(scene);
        stage.show();
    }

    public static class Entry {

        private final SimpleStringProperty value;

        private Entry( final String value ) {
            this.value = new SimpleStringProperty(value);
        }

        public SimpleStringProperty valueProperty() {
            return value;
        }

    }
}

Steps to reproduce:
1. Launch application
2. Use the "+" or "-" button to change the stage height 
3. Try to select a different item in the TableView. If selection is still possible, go to step 2.

Finding a stage height where this problem occurs seems to depend on the screen scale.
With a scale of 100 % I can reproduce the issue with at least the following heights:
1018, 1022, 1038, 1042, 1044, 1045

I would be more than happy if someone could take a look at this problem.

Best regards
Florian Kroiss


More information about the openjfx-dev mailing list