我正在尝试重新缩放窗格以适合显示器的分辨率。原始窗口用于高清显示。
现在我已经尝试使用
public void initialize(URL location,ResourceBundle resources) {
Rectangle2D screenBounds = Screen.getPrimary().getBounds();
double x = screenBounds.getWidth();
double y = screenBounds.getHeight();
double ratioX = x/1366;
double ratioY = y/768;
System.out.println(ratioX);
System.out.println(ratioY);
ObservableList<Node> l = pane.getchildren();
for (Node n : l) {
n.setScaleX(ratioX);
n.setScaleY(ratioY);
n.setLayoutX(n.getLayoutX() * ratioX);
n.setLayoutY(n.getLayoutY() * ratioY);
}
但是setScaleX和setScaleY扩展Node的方式是,该Node不会源自给定LayoutX的LayoutY。它向左右扩展。
如何以节点的左上角始终位于已定义的layoutX和layoutY的方式缩放节点