由于垂直滚动条,JavaFX TableColumns的标头未与单元格对齐 [英] JavaFX TableColumns' headers not aligned with cells due to vertical scrollbar

查看:158
本文介绍了由于垂直滚动条,JavaFX TableColumns的标头未与单元格对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

花了最后几个小时在网络上搜索此问题后,我决定需要您的帮助.

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

问题类似于此主题: Javafx:Tableview标头是与行不对齐

这里没有提供任何答案,我想我的情况也略有不同:

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

我有一个正确设置的TableView,其中包含重复使用的CellFactories和CellValueFactories.从数据角度来看,一切都按我的预期方式工作100%.但是,一旦我在表中填充的行超过了视图所能显示的行数,它自然就会开始显示垂直滚动条.从那一刻起(请参阅第一个屏幕截图),列标题不再与列对齐.似乎恰好是滚动条的宽度扭曲了宽度分布(我使用的是ConstraintResizePolicy,其中包含一些固定宽度的列,其余部分则依赖于计算宽度,否则会正常工作).

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()

我不知道所有这些都有意义,但我仍然尝试过,并且没有一个使列标题与应用程序启动时的列保持一致.

欢迎任何建议. 我觉得共享代码在这里没有帮助,但是请问您是否需要特定的东西.该视图是由SceneBuilder 8构建的,由AnchorPane,中间的TableView和6个TableColumns组成.

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.

非常感谢!

推荐答案

我遇到了同样的问题.似乎是个错误.试试这个.对我有用

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

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

这篇关于由于垂直滚动条,JavaFX TableColumns的标头未与单元格对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆