在坐标处放置方形时的JavaFX问题 [英] JavaFX issue when placing square at coordinates

查看:168
本文介绍了在坐标处放置方形时的JavaFX问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我从矩形中得到以下代码

so i have the following code from a Rectangle

rect.setX(10);

我还有

rect.setY(20);

但每当我编译应用程序时,矩形总是移动到应用程序框架的中间。

but whenever i compile the application the rectangle is always moved to the middle of the application's frame.

使用的进口:

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.shape.*;
import javafx.scene.Scene;
import javafx.geometry.Insets;
import javafx.scene.input.MouseEvent;
import javafx.event.EventHandler;
import javafx.scene.input.KeyCombination;
import javafx.scene.paint.Color;
import javafx.scene.layout.*;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;


推荐答案

考虑将矩形添加到 StackPane ,您必须使用translate属性来移动矩形。尝试:

Considering that the rectangle is added to a StackPane, you must use the translate properties to move the rectangle. Try :

rect.setTranslateX(10);
rect.setTranslateY(20);

这篇关于在坐标处放置方形时的JavaFX问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆