在tableView JavaFx中将CONSTRAINED_RESIZE_POLICY设置为无首列(行数)的列 [英] Set CONSTRAINED_RESIZE_POLICY for columns without first (for number of row) in tableView JavaFx

查看:80
本文介绍了在tableView JavaFx中将CONSTRAINED_RESIZE_POLICY设置为无首列(行数)的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有tableView与第一列的行号.我想为所有列设置CONSTRAINED_RESIZE_POLICY,而无需先进行设置.

I have tableView with first column for row number. I would like to set CONSTRAINED_RESIZE_POLICY for all columns without first.

我做了:

//First column implementation
column.setPrefWidth(40);
column.setResizable(false);
... //Make other columns
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

因此,我有第一列具有所选宽度的列,但其他列的宽度比上面代码中没有最后一行的宽度要宽,但仍然有一个额外的空列.

So I have first column with width I chose but other are wider than without last line in code above but still there is one additional void column.

还有另一个问题,因为我想将列的大小调整为列中最长的文本的长度(第一列需要它),但是我只找到了很长且棘手的解决方案的旧答案.有什么简单的解决方案(方法)吗?

And I have another question because I looked for resizing column to length of the longest text in column (I need it for first column) but I only found old answers with very long and tricky solutions. Is there any simple solution (method) to do it?

我发现,当我尝试手动调整列的大小时,只需单击以调整列的大小,它们便会正确地调整大小(与CONSTRAINED相同),所以我有一个问题,为什么他们并没有像我上面描述的那样从一开始就调整大小,而是在尝试手动调整大小之后.我认为问题出在第一列的setResizable false上,但是我该如何修复呢?

I found that when I try to manually resize columns, that they resize properly (as they should with CONSTRAINED) after only click to resize one of columns so I have a question, why they didn't resize from the start like I described above but after trying to manual resize. I think that problem is with setResizable false on first column but how can I repair this?

推荐答案

我找到了解决方案.要使其他列为CONSTRAINED_RESIZE_POLICY,必须设置第一列的大小,如下所示:

I found solution. To make other columns CONSTRAINED_RESIZE_POLICY there must be set size of the first column like below:

column.setMinWidth(40);
column.setMaxWidth(40);

,它不需要行setResizable(false).

and it's working without line setResizable(false).

这篇关于在tableView JavaFx中将CONSTRAINED_RESIZE_POLICY设置为无首列(行数)的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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