JavaFX,TableView中的列在移动后会重新调整大小 [英] JavaFX, columns in TableView resize after been moved

查看:452
本文介绍了JavaFX,TableView中的列在移动后会重新调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TableView,其中的列数超过了屏幕宽度.第一次加载时,所有列的宽度都相同,但是,一旦我移动其中一个,所有列的大小都会被调整为等于该列单元格中数据最大宽度的宽度.

I have a TableView with a number of columns that exceeds the screen width. When it's loaded the first time, all columns have the same width but, as soon as I move one of these, all of them are resized to a width equals to the maximum width of data inside the cells of the column.

我的问题是:是否可以禁用此行为或使其起作用,直到TableView首次加载?

My question is: is it possible to disable this behavior or to make it works till the first load of the TableView?

PS: TableView加载为空,然后按下一个填充数据的按钮,因为在发送数据请求之前您需要输入一些关键字段.

PS: the TableView is loaded empty, then pressing a button it is filled with data, because you have some key field to input before sending the request for data.

推荐答案

经过一些测试,我发现所描述行为的原因是:没有明确设置列prefWidth.

After some tests I found that the reason of the behaviour described was: not explicity setting the column prefWidth.

如果您创建的Tableview自开始以来是内部数据,并且不设置列prefWidth ,则所有列的宽度都将与数据的最大宽度匹配;如果更改了列的宽度,则只要拖动一个宽度将恢复为原始值.

If you create a Tableview with data inside since the beginning and without setting column prefWidth, all columns width will match the data maximum width and, if you change column width, as soon as you drag one the width will be restored to the original value.

如果创建的Tableview自开始并设置列prefWidth 以来一直在内部,则所有列的宽度都将与设置的值匹配;如果在拖动前放大列,则该列的宽度将保持不变

If you create a Tableview with data inside since the beginning and setting column prefWidth, all columns width will match the setted value and if you enlarge a column before dragging one then that column width will remain unchanged.

我不知道这是错误还是想要的.但是,谢谢您jewelsea的建议.

I have no idea if this is a bug or it is wanted. However thank you jewelsea for the suggestions.

这篇关于JavaFX,TableView中的列在移动后会重新调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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