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

你可能感兴趣的:(JavaFX,Java,JavaFX)