如何实现整个 SplitPane 的按比例调整大小?
public class JfxSplitPaneTest extends Application {
@Override
public void start(Stage stage) throws Exception {
SplitPane split = new SplitPane();
StackPane child1 = new StackPane();
child1.setStyle("-fx-background-color: #0000AA;");
StackPane child2 = new StackPane();
child2.setStyle("-fx-background-color: #00AA00;");
StackPane child3 = new StackPane();
child3.setStyle("-fx-background-color: #AA0000;");
split.getItems().addAll(child1, child2, child3);
//split.setDividerPositions(0.1f, 0.6f, 0.9f)
stage.setScene(new Scene(split, 400, 300));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
启动程序:
按照我喜欢的方式设置分隔线:
让窗口宽度变得非常小(我继续并将其变得更小,没有图片):
调整大小并观察分隔线既不是我设置的方式也不是程序启动时的方式。
这样做使它更接近我的预期:
child1.setMinWidth(Region.USE_PREF_SIZE)
child1.setPrefWidth(100)
child2.setMinWidth(Region.USE_PREF_SIZE)
child2.setPrefWidth(200)
child3.setMinWidth(Region.USE_PREF_SIZE)
child3.setPrefWidth(300)
除了分隔线最初位于错误的位置(直到我调整分割窗格的大小,1px 就足够了),并且当缩小窗口宽度时,分隔线位于组件内部。
请问我该如何进行这项工作?
尝试像 AS3Boyan 所说的那样设置除数
split.setDividerPositions(0.1f, 0.6f, 0.9f)
并添加以下内容:
如何避免 SplitPane 在窗口大小调整时调整其中一个窗格的大小?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)