简体   繁体   English

在父级边界之外转换节点会将最小大小更改为当前大小

[英]Translating a node outside of parents bounds changes minimum size to current size

When I translate a node outside of the bounds of it's parent. 当我在父节点的边界之外翻译节点时。 The minimum size of the parent of the parent is set to it's current size. 父母的父母的最小尺寸被设置为其当前尺寸。 You can see it with this demo: 您可以通过此演示看到它:

package com.neonorb.test;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

import java.io.IOException;

/**
 * Created by chris on 7/20/15.
 */
public class Test extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws IOException {
        Label label = new Label("translating label");
        Label markerLabel = new Label("marker label");
        Button button = new Button("button");
        VBox leftSpace = new VBox();
        Label leftLabel = new Label("left space");
        leftSpace.getChildren().add(leftLabel);
        Rectangle rectangle = new Rectangle();
        rectangle.setFill(Color.RED);
        rectangle.heightProperty().bind(leftSpace.heightProperty());
        rectangle.widthProperty().bind(leftSpace.widthProperty());
        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                new Thread() {
                    public void run() {
                        Platform.runLater(() -> label.setTranslateY(1000.0));
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        Platform.runLater(() -> label.setTranslateY(0.0));
                    }
                }.start();
            }
        });
        BorderPane borderPane = new BorderPane();
        BorderPane center = new BorderPane();
        center.setCenter(label);
        center.setBottom(markerLabel);
        borderPane.setCenter(center);
        borderPane.setTop(button);
        borderPane.setLeft(leftSpace);
        borderPane.setRight(rectangle);
        primaryStage.setScene(new Scene(borderPane));
        primaryStage.show();
    }
}

The reason for the side bar things (the VBox and Rectangle ) is because they exist in my real application. 出现侧栏内容( VBoxRectangle )的原因是因为它们存在于我的实际应用程序中。 The VBox just holds more content, and the Rectangle is there to keep the center components centered (normally transparent, but here it is colored for visibility). VBox只能容纳更多内容,而Rectangle可以使中心组件居中放置(通常是透明的,但是这里为便于查看而着色)。 As you can see, the width and height of the rectangle are binded to the VBox 's height: 如您所见,矩形的宽度和高度绑定到VBox的高度:

rectangle.heightProperty().bind(leftSpace.heightProperty());
rectangle.widthProperty().bind(leftSpace.widthProperty());

To reproduce the problem, you can increase the height of the window a little (about an inch), then hit the button. 要重现该问题,您可以将窗口的高度稍微增加一点(大约一英寸),然后点击按钮。 The node will be translated down 1000 pixels and back. 该节点将向下平移1000像素。 Now try to shrink the window, the text at the bottom, ("marker label"), will start to be hidden by the bottom of the window. 现在尝试缩小窗口,底部的文本(“标记标签”)将开始被窗口底部隐藏。

我通过使用Region而不是Rectangle并设置了它的首选大小来修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM