JavaFX 尺寸&边界&位置&坐标

尺寸&边界&位置&坐标

min max pre
Button button = new Button("ButtonButtonButtonButton");
button.setMinWidth(100);
button.setPrefWidth(120);
button.setMaxWidth(150);

button.getWidth() //父组件提供的宽度
//类似 wrap_content
button.setPrefWidth(Button.USE_COMPUTED_SIZE);
//Control.USE_COMPUTED_SIZE 类似 wrap_content
//Control.USE_PREF_SIZE 固定值

位置&坐标

button.setLayoutX(100);
button.setLayoutY(100);

//父组件中的坐标
double layoutX = button.getLayoutX();
double layoutY = button.getLayoutY();

//当前组件边界框范围, 不包含 Effect
Bounds layoutBounds = button.getLayoutBounds();
//当前组件宽高
double width = layoutBounds.getWidth();
double height = layoutBounds.getHeight();
//左上角X
double minX = layoutBounds.getMinX();
//左上角Y
double minY = layoutBounds.getMinY();
//右下角X
double maxX = layoutBounds.getMaxX();
//右下角Y
double maxY = layoutBounds.getMaxY();

//当前坐标转父坐标
Point2D localToParent = button.localToParent(minX, minY);
double parentX = localToParent.getX();
double parentY = localToParent.getY();
//当前坐标转场景坐标
Point2D localToScene = button.localToScene(minX, minY);
double sceneX = localToScene.getX();
double sceneY = localToScene.getY();
//当前坐标转屏幕坐标
Point2D localToScreen = button.localToScreen(minX, minY);
double screenX = localToScreen.getX();
double screenY = localToScreen.getY();

边界

//当前组件边界框范围, 不包含 Effect
Bounds layoutBounds = button.getLayoutBounds();
//当前组件包含 Effect 的边界框范围
Bounds boundsInLocal = button.getBoundsInLocal();
//当前组件在父组件的边界框范围
Bounds boundsInParent = button.getBoundsInParent();
  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值