gpt4 book ai didi

css - 如何在 JavaFX 的 SplitPanes 上将分隔符位置绑定(bind)到像素而不是百分比?

转载 作者:太空宇宙 更新时间:2023-11-04 09:22:59 25 4
gpt4 key购买 nike

调整窗口大小后,我的 SplitPane 的分隔线会根据给定的百分比移动到另一个位置(例如:dividerPositions="0.05")。

但我希望它在调整大小后保持在之前设置的相同位置(就像它绑定(bind)到像素大小而不是百分比)。我不希望它在调整其父 Pane 大小时“移动”(遵循百分比约束)。

是否有可能以某种方式做到这一点?(我想最好从代码中解决这个问题,CSS 解决方案对我来说是次要的)

对我来说,完美的解决方案与此类似:

<SplitPane orientation="VERTICAL" dividerPositionFromTop="100px" 
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" >
...
</SplitPane>

据我所知,遗憾的是 dividerPositionFromTop 不存在。

最佳答案

您可以将监听器添加到 SplitPaneheightProperty 并重新计算百分比值:

SplitPane splitPane = new SplitPane();

splitPane.heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
double height = splitPane.getHeight();
double dividerPositionFromTop = 100;
splitPane.setDividerPosition(0, dividerPositionFromTop/height);
}
});
splitPane.getItems().addAll(new TextArea("1"), new TextArea("2"));
splitPane.setOrientation(Orientation.VERTICAL);

关于css - 如何在 JavaFX 的 SplitPanes 上将分隔符位置绑定(bind)到像素而不是百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41371929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com