how to make child auto-resize (child is Pane, parent is VBox) in javafx

Rui Zhou

I have 2 questions

1.in a javafx application, I want to put the child(crosshairArea) at the left-top corner of its parent, with 1/2 width and height as well. think I can do that via override the parent function "layoutChildren" (VBox), is there other way to do that? e.g. property binding?

2.initially VBox will occupy the full scene area, how to make(relocate) it to the half-bottom of scene?

public class Crossh extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) {        
        VBox root = new VBox(5);
        // root.setPadding(new Insets(20,20,20,20));
        root.setStyle("-fx-border-color:red");

        Pane crosshairArea = new Pane();
        crosshairArea.maxWidthProperty().bind(root.widthProperty());
        crosshairArea.setStyle("-fx-border-color:black");       

        root.getChildren().add(crosshairArea);
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Location Crosshair");
        stage.setWidth(900);
        stage.setHeight(700);        
        stage.show();
    }
}
ItachiUchiha

For your first question Have you tried the height property of VBox. For example

root.heightProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> arg0,
                Number arg1, Number arg2) {
            crosshairArea.setPrefHeight(arg2.doubleValue()/2);

    }
});

For your second question, you will have to put something on top of VBox to occupy the size on the top or you can set the alignment of VBox to Pos.BOTTOM

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to make child class call parent class __init__ automatically?

From Dev

How to decide and make REST calls corresponding to parent-child relationship

From Dev

JavaFX: FXML: How to make the child to extend its size to fit the parent pane?

From Dev

Resize a pane in javafx by dragging it

From Dev

How to Make Parent-Child-Parent scope stay inside of Parent?

From Dev

How to make a parent div stretch according to it's child's content?

From Dev

XML AUTO Parent or child?

From Dev

How to make the parent thread wait for the child thread to complete - C#

From Dev

How to make parent element hide but child inside be visible

From Dev

How to make splay tree with parent and child pointers in lisp

From Dev

How to make child div scrollable when it exceeds parent height?

From Dev

JavaFX-CSS: How to "move" style of parent to a child?

From Dev

How to make a return from a child function cause a return to the parent function?

From Dev

How to make child composite fill parent in swt

From Dev

Setting VBox.vgrow on a child element of <fx:root> in JavaFX 8

From Dev

Make a child as wide as the parent of parent

From Dev

How to refresh parent window after closing child window in JavaFX?

From Dev

How do I make my VBox and Label resize according to texts in label in JavaFx?

From Dev

Auto resize child div to fill available space of parent div

From Dev

JavaFX: Remove a child from Vbox

From Dev

Auto resize child div to fill available space of parent div

From Dev

How to Make Parent-Child-Parent scope stay inside of Parent?

From Dev

How to make parent container resize to child container correctly without using min-height

From Dev

JavaFX-CSS: How to "move" style of parent to a child?

From Dev

Vbox Parent, Pane Child overlapping other components javafx

From Dev

How to make a child the parent of it's parent using jQuery?

From Dev

How to make child span collapse with parent

From Dev

How to make object with parent child thing?

From Dev

Child div auto resize to its parent

Related Related

  1. 1

    how to make child class call parent class __init__ automatically?

  2. 2

    How to decide and make REST calls corresponding to parent-child relationship

  3. 3

    JavaFX: FXML: How to make the child to extend its size to fit the parent pane?

  4. 4

    Resize a pane in javafx by dragging it

  5. 5

    How to Make Parent-Child-Parent scope stay inside of Parent?

  6. 6

    How to make a parent div stretch according to it's child's content?

  7. 7

    XML AUTO Parent or child?

  8. 8

    How to make the parent thread wait for the child thread to complete - C#

  9. 9

    How to make parent element hide but child inside be visible

  10. 10

    How to make splay tree with parent and child pointers in lisp

  11. 11

    How to make child div scrollable when it exceeds parent height?

  12. 12

    JavaFX-CSS: How to "move" style of parent to a child?

  13. 13

    How to make a return from a child function cause a return to the parent function?

  14. 14

    How to make child composite fill parent in swt

  15. 15

    Setting VBox.vgrow on a child element of <fx:root> in JavaFX 8

  16. 16

    Make a child as wide as the parent of parent

  17. 17

    How to refresh parent window after closing child window in JavaFX?

  18. 18

    How do I make my VBox and Label resize according to texts in label in JavaFx?

  19. 19

    Auto resize child div to fill available space of parent div

  20. 20

    JavaFX: Remove a child from Vbox

  21. 21

    Auto resize child div to fill available space of parent div

  22. 22

    How to Make Parent-Child-Parent scope stay inside of Parent?

  23. 23

    How to make parent container resize to child container correctly without using min-height

  24. 24

    JavaFX-CSS: How to "move" style of parent to a child?

  25. 25

    Vbox Parent, Pane Child overlapping other components javafx

  26. 26

    How to make a child the parent of it's parent using jQuery?

  27. 27

    How to make child span collapse with parent

  28. 28

    How to make object with parent child thing?

  29. 29

    Child div auto resize to its parent

HotTag

Archive