我想在网格窗格中添加一个不可见的行。然后,我想根据用户选择显示和隐藏它。我设法使常规功能正常工作,但是问题是当隐藏行内容时,会有额外的空间。我不确定这是实际的行还是vgap?无论如何,我想摆脱这些多余的空间。
这是我的网格:
public class CustomGrid extends GridPane{
public CustomGrid() {
this.setHgap(20);
this.setVgap(20);
ColumnConstraints firstColConstraints = new ColumnConstraints();
firstColConstraints.setHalignment(HPos.RIGHT);
firstColConstraints.setPercentWidth(50.0);
firstColConstraints.setHgrow(Priority.ALWAYS);
ColumnConstraints secondColConstraints = new ColumnConstraints();
ColumnConstraints thirdColConstraints = new ColumnConstraints();
thirdColConstraints.setHgrow(Priority.ALWAYS);
thirdColConstraints.setHalignment(HPos.LEFT);
this.getColumnConstraints().addAll(firstColConstraints, secondColConstraints, thirdColConstraints);
VBox.setMargin(this, new Insets(10, 0, 50, 0));
}
我添加了内容然后像这样隐藏了它
Pane content = new Pane()
pane.setVisible(false);
pane.setManaged(false);
add(content, 0, 1);
当用户使它可见时,我对此感到满意,但是当它被隐藏时,各行之间存在额外的间隙。谁能告诉我解决办法。
谢谢。
最佳答案
如评论(link to comment)中所述:
隐藏时将高度更改为0。
关于java - 在javafx gridpane中添加不可见的行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42628167/