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();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章