如果 GridPane 行的内容既禁用又不可见,是否可以缩小该行?
当我将节点设置为disable=true和visible=false时,单元格仍然占用空间。
如果我有 8 行,并且只有第一行和最后一行可见,我不希望空行占用太多空间。好像只有两行。
我能找到的唯一“解决方案”是将大小设置为零。但我不认为这是一个好的解决方案。我必须存储最小/最大大小,以便在节点再次启用/可见时将其设置回来。
也许 CSS 可以帮助提供更好的解决方案?
package com.company;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;
public class App extends Application {
public static void main(String[] args) {
launch(args);
}
/* (non-Javadoc)
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
@Override
public void start(Stage stage) throws Exception {
Label label1 = new Label("Text");
Label label2 = new Label("Text");
Label label3 = new Label("Text");
label2.setDisable(true);
label2.setVisible(false);
GridPane root = new GridPane();
root.setGridLinesVisible(true);
root.add(label1, 0, 0);
GridPane.setVgrow(label1, Priority.NEVER);
root.add(label2, 0, 1);
GridPane.setVgrow(label2, Priority.NEVER);
root.add(label3, 0, 2);
GridPane.setVgrow(label3, Priority.NEVER);
stage.setScene(new Scene(root));
stage.setWidth(300);
stage.setHeight(300);
stage.setTitle("JavaFX 8 app");
stage.show();
}
}
如果不希望父节点布局节点,可以设置managed
节点的属性为false
.
下面的图像显示了当我在代码中使用以下行时布局的差异:
label2.setManaged(false);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)