缩小矩形的高度以适应javafx中的窗口

时间:2015-03-21 21:20:59

标签: java javafx height rectangles

我目前正在开发一个依赖于通过矩形表示文件大小的项目。然而,我已经坚持了很长一段时间,将高度缩放到可以放入舞台内部的大小。这是项目的一个关键部分,因为它允许用户从他们机器上的任何目录直观地比较他们正在查看的文件的大小。 编辑:我尝试添加图像,但我还没有足够的声誉:(。 http://tinypic.com/r/2e56pol/8

1 个答案:

答案 0 :(得分:0)

为什么不使用以下方法将矩形的高度绑定到场景中

rectangle.heightProperty().bind(scene.heightProperty());

一个完整的例子:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class DemoTabPane extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Rectangle rectangle = new Rectangle(20,20,200,200);
        rectangle.setStroke(Color.BLACK);
        Scene scene = new Scene(new HBox(rectangle), 100, 100);
        rectangle.heightProperty().bind(scene.heightProperty());
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
相关问题