AfroChase AfroChase - 5 months ago 220
Java Question

Horizontal scroll bar hides the last row in a TableView (JavaFX)

My problem is this: when a

TableView
has more rows than its height supports, a vertical scroll bar and a horizontal scroll bar appears. If the user goes to the bottom of the TableView and update the list that fills the TableView, the TabletView shows correctly all the ítems but the horizontal scroll bar partially hides the last row, if the user tries to scroll to bottom, the vertical scroll bar does not go to bottom and the last row remains hidden.

Question: is there any way or method that prevents the hiding of the last row in this situation?

Answer

If you actually do not need the horizontal scrollbar at all, you can do the following.

Set the column resize policy of the table view to CONSTRAINED_RESIZE_POLICY:

tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

Simple policy that ensures the width of all visible leaf columns in this table sum up to equal the width of the table itself.

Beside this, you can ensure that the horizontal scrollbar is invisible all the time.

To achieve that you can add the following lines to your CSS file:

.table-view .scroll-bar:horizontal .increment-arrow,
.table-view .scroll-bar:horizontal .decrement-arrow,
.table-view .scroll-bar:horizontal .increment-button,
.table-view .scroll-bar:horizontal .decrement-button {
    -fx-padding:0;
}