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

╄→尐↘猪︶ㄣ 提交于 2019-12-06 04:14:29

问题


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:

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!


回答1:


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

Platform.runLater(() -> tableView.refresh());


来源:https://stackoverflow.com/questions/37423748/javafx-tablecolumns-headers-not-aligned-with-cells-due-to-vertical-scrollbar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!