使用TableView.CONSTRAINED_RESIZE_POLICY时,TableView标头宽度错误 [英] Wrong TableView header width when using TableView.CONSTRAINED_RESIZE_POLICY

查看:294
本文介绍了使用TableView.CONSTRAINED_RESIZE_POLICY时,TableView标头宽度错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它实际上是一个已知的bug并且钢铁为JavaFX打开了一个错误报告,您可能会发现
此处

It's actualy a known bug and steel opened a bug report for JavaFX, which you may found here.

说明是:

当ColumnResizePolicy设置为CONSTRAINED_RESIZE_POLICY并且表的数据不适合可用的tableview的高度(垂直滚动可见)时,标题的宽度不正确 - 但仅当TableView没有聚焦时。当TableView获得焦点时,标题正在获得适当的宽度。

When ColumnResizePolicy is setted to CONSTRAINED_RESIZE_POLICY and table have data that is not fit in available tableview's height (vertical scroll is visible) then headers have improper width - but only when TableView is not focused. When TableView get focus then headers are getting proper width.

问题是,我真的需要以某种方式修复它,但我找不到任何解决方法来做到这一点。

The problem is, I really need to fix it somehow, but i can't find any workaround to do that.

我尝试过:

refresh()
只是跳出并且在

refresh() and just "jumping" out and in

otherGUIObject.requestFocus();
tableView.requestFocus(); //or getSelectionModel().Select(0)    
otherGUIObject.requestFocus();

tableView.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

但似乎没有任何效果。有什么想法吗?
谢谢!

But nothing seems to work. Have someine any ideas? Thanks!

推荐答案

你在正确的轨道上:你应该打电话给 requestFocus() TableView 上的

You are on the correct track: you should call requestFocus() on the TableView.

以下代码段的问题(来自您的问题)

The problem with the following snippet (from your question)

otherGUIObject.requestFocus();
tableView.requestFocus(); //or getSelectionModel().Select(0)    
otherGUIObject.requestFocus();

当你打电话给 requestFocus() focusedProperty 按预期将节点设置为 true ,但这并不意味着控件实际上集中在GUI上(布局已更新) - 因为只有在JavaFX应用程序线程有时间更新它时才会更新。在代码段中,您连续调用三个 requestFocus 调用:前两个将被优化,因此只执行最后一个(最有可能)。

is that when you call requestFocus(), the focusedProperty of the Node is set to true as expected, but it does not mean, that the control actually gets focused on the GUI (the layout is updated) - as it is only updated when the JavaFX application thread has time to update it. In the snippet you make three requestFocus calls in a row: the first two will be optimized, therefore only the last one is executed (most probably).

解决方法是调用 TableView 上的rel =nofollow noreferrer> requestLayout 方法焦点也在GUI上更新。之后,您可以将焦点设置在任何其他节点上(在我使用过的示例中 focusOwnerProperty 场景获取当前选择的节点,然后在 TableView 集中后,我将重点放在节点再次)。

The solution is to call the requestLayout method on the TableView after the focus is requested to ensure that the focus is updated on the GUI too. Afterwards you can set the focus on any other Node (in the example I have used focusOwnerProperty of Scene to get which Node is currently selected, then after the TableView was focused, I focus this Node again).

示例

// The current focus owner on the Scene
Node focusOwner = scene.getFocusOwner();

table.requestFocus();
table.requestLayout();

// Request focus on the currently focused Node
if(focusOwner != null)
    focusOwner.requestFocus();
else
    // request focus on any Node you want
    textField.requestFocus();

这篇关于使用TableView.CONSTRAINED_RESIZE_POLICY时,TableView标头宽度错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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