如何在 HBox 中隐藏一个项目,并让该项目使用的空间可供其他项目使用。
TitledPane legendPane = new TitledPane("Legend", _legend);
legendPane.setVisible(false);
LineChart chart = new LineChart<Number, Number>(_xAxis, _yAxis);
HBox hbox = new HBox(5);
hbox.getChildren().addAll(legendPane, chart);
在上面的代码中,我希望图表节点在隐藏图例 Pane 时使用所有可用空间。
最佳答案
在调用 legendPane.setVisible 之前,调用:
legendPane.managedProperty().bind(legendPane.visibleProperty());
Node.managed属性防止场景中的节点影响其他场景节点的布局。
关于JavaFX HBox 隐藏项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12200195/