JavaFX网格窗格:展开按钮可填充多个单元格



使用JavaFX的GridPane容器,如何设置按钮(或其他任何东西)以水平展开,直到它填充所有指定的单元格?

我使用以下行将按钮添加到我的GridPane:

grid.add(button, 3, 0, 3, 1);

但按钮的宽度只有文本的宽度,大约有2.5个单元格。我希望它完全占据所有3个指定的单元格。

您可以进行

// allow button to grow:
button.setMaxWidth(Double.MAX_VALUE);
// ask GridPane to make button fill it's cells:
GridPane.setFillWidth(button, true);

最新更新