从heightProperty()和widthProperty()中获取最大值和最小值

BingQuan :

有没有类似Math.max(num1, num2)比较两个DoubleProperty的代码?我目前正在尝试显示一个圆形(从Pane延伸),该圆形可以根据窗口的大小自动调整大小。我想尝试在两者之间取较小的值来设置圆的半径。

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class DisplayCircle extends Application {
   @Override
   public void start(Stage primaryStage) {
      Scene scene = new Scene(ResizableCircle(), 400, 300);
      primaryStage.setTitle("DisplayCircle");
      primaryStage.setScene(scene);
      primaryStage.show();
   }

   public class ResizableCircle extends Pane {
      public ResizableCircle() {
         Circle c = new Circle(getWidth()/2, getHeight()/2);
         c.centerXProperty().bind(widthProperty().subtract(10));
         c.centerYProperty().bind(heightProperty().subtract(10));


         // Need help setting the radius and binding it


         getChildren().add(c);
   }
}
女士 :

您可以使用Bindings.max(ObservableNumberValue op1, ObservableNumberValue op2)Bindings.min(ObservableNumberValue op1, ObservableNumberValue op2)将绑定ObservableNumberValue到其他两个可观察值的最小值或最大值:

DoubleProperty min = new SimpleDoubleProperty();
DoubleProperty max = new SimpleDoubleProperty();

min.bind(Bindings.min(widthProperty(), heightProperty()));
max.bind(Bindings.max(widthProperty(), heightProperty()));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章