Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX TableColumns' headers not aligned with cells due to vertical scrollbar

Tags:

javafx-8

after having spent the last few hours searching the web for this issue I decided that I need your help.

The issue is similar to this topic: Javafx: Tableview header is not aligned with rows

No answer has been provided there and also, I think, my case is slightly different:

Screenshot directly after launch

Screenshot after scrolling or clicking

I have a properly setup TableView with reused CellFactories and CellValueFactories. Data-wise, everything works 100% the way I intended. However once I populated my table with more rows than my view can show it naturally started to show a vertical scrollbar. From that moment on (see first screenshot) the column headers weren't aligned with the columns anymore. It appears that it is exactly the width of the scrollbar that distorted the widths distribution (I'm using ConstraintResizePolicy with a few fixed width columns and the rest relying on computed width, again, otherwise working flawlessly).

As soon as I scroll with the mouse wheel, click on an entry, tab into focus or resize the window/view, the headers snap into place (see second screenshot).

Based on the topic posted in the beginning, I think this is a bug and I'm therefore not only looking for a solution (which might not exist) but also for a workaround. I tried:

  • table.scrollTo()
  • table.scrollToColumnIndex()
  • table.layout()
  • table.requestFocus()
  • table.requestLayout()
  • table.refresh()

I know not all of those make sense but still I tried and none of them made the column headers be in line with their columns on application launch.

Every suggestion is welcomed. I don't feel that sharing code helps here, but ask if you want something specific. The view was built with SceneBuilder 8 and consists of an AnchorPane, a TableView in the middle, and 6 TableColumns, nothing else.

Thank you very much!

like image 988
Dr. Cashberg Avatar asked May 24 '16 20:05

Dr. Cashberg


2 Answers

I've had the same problem. It seems a bug. Try this. It works for me

Platform.runLater(() -> tableView.refresh());
like image 193
Mobin Taneh Avatar answered Oct 23 '22 05:10

Mobin Taneh


I also have the situation of TableColumns' Headers not aligend with cells.But I am not because Scrollbar.I am because of setting a border color for cells.After the CSS modified, I got the correct result.

Incorrect CSS:

.table-row-cell {
  -fx-border-color: black;
}

changed to:

.table-row-cell {
  -fx-table-cell-border-color: black;
}

Reference documentation: https://community.oracle.com/tech/developers/discussion/2505963/tableview-column-headers-do-not-line-up-with-rows

like image 29
Json Exception Avatar answered Oct 23 '22 03:10

Json Exception