TableView的列多于指定的列 [英] TableView has more columns than specified

查看:308
本文介绍了TableView的列多于指定的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaFX 2中使用TableView时,似乎神奇地添加了一列,而不是调整现有列的大小.请查看以下屏幕截图.

When using a TableView in JavaFX 2, there seems to be magically one column added instead of resizing the existing ones. Please see the following screenshot.

我期望/想要的:两列都应有50%的空间,不应添加第三列(未命名/空).

What I would expect/want: Both column shall have 50% of space, no third (unnamed/empty) column shall be added.

使用Scene Builder创建的FXML代码:

Created using Scene Builder, FXML code:

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<BorderPane id="BorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
  <top>
    <TableView prefHeight="200.0" prefWidth="200.0">
      <columns>
        <TableColumn prefWidth="75.0" text="Column X" />
        <TableColumn prefWidth="75.0" text="Column X" />
      </columns>
    </TableView>
  </top>
</BorderPane>

推荐答案

使用

table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

这样做可以确保表列标题中的多余空间将在各列之间分配.在此分布中,当然会考虑列的最大和最小宽度.
默认情况下,在表列最初采用其首选宽度的地方使用TableView.UNCONSTRAINED_RESIZE_POLICY.

By doing this you ensure that the extra space in table column header will be distributed among the columns. In this distribution the columns' max and min widths are taken into account of course.
By default the TableView.UNCONSTRAINED_RESIZE_POLICY is used where the tablecolumns will take their preferred width initially.

这篇关于TableView的列多于指定的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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