我有一个窗口,需要保持正方形。我的代码是
primaryStage.minHeightProperty().bind(scene.widthProperty());
primaryStage.minWidthProperty().bind(scene.heightProperty());
当我尝试缩小正方形的大小时,它确实会进行调整,但是存在问题。有时一个边会比另一个边稍微短或长一些。有没有解决方法?我当前使用的代码是否有问题?
private val DEF_PAD = 6.0
chart.paddingProperty.bind(boundValue(stage.widthProperty, stage.heightProperty) {
// Maintain a square plot with padding
val w = stage.getWidth
val h = stage.getHeight
val extra = DEF_PAD + 0.5 * Math.abs(w - h)
if (w > h) {
new Insets(DEF_PAD, extra, DEF_PAD, extra)
} else if (h > w) {
new Insets(extra, DEF_PAD, extra, DEF_PAD)
} else {
new Insets(DEF_PAD)
}
})