0

ノードを親の境界外に移動すると。親の親の最小サイズは、現在のサイズに設定されます。このデモでそれを見ることができます:

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();
    }
}

サイド バーのもの (VBoxRectangle) の理由は、それらが実際のアプリケーションに存在するためです。はより多くのVBoxコンテンツを保持するだけであり、Rectangleは中央のコンポーネントを中央に維持するためにあります (通常は透明ですが、ここでは見やすくするために色が付けられています)。ご覧のとおり、長方形の幅と高さは の高さにバインドされていますVBox

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

問題を再現するには、ウィンドウの高さを少し (約 1 インチ) 上げてから、ボタンを押します。ノードは 1000 ピクセル下に移動して戻ります。ウィンドウを縮小してみると、下部のテキスト (「マーカー ラベル」) がウィンドウの下部に隠れ始めます。

4

1 に答える 1

0

Regiona の代わりに aを使用して修正し、Rectangle優先サイズを設定しました。

于 2015-08-29T15:58:20.080 に答える