简体   繁体   中英

What happens when you call getChildren on it's own?

I'm relatively new to Java, especially Javafx and GUIs. I've been working on this code but I'm having some trouble understanding what THE VERY LAST LINE is doing. I understand the second last line is adding all the components to the container 'p', but what happens when you call getChildren() without a container before it. Anyways, any help is appreciated.

import javafx.scene.control.Button;
import javafx.scene.layout.Pane;

public class DVDButtonPane extends Pane {

    public DVDButtonPane(){
        Pane p = new Pane();

        Button add = new Button("Add");
        add.setPrefSize(95, 30);
        add.relocate(0, 0);
        add.setStyle("-fx-font: 12 arial; -fx-base: rgb(0,100,0); -fx-text-fill: rgb(255,255,255);");

        Button delete = new Button("Delete");
        delete.setPrefSize(90, 30);
        delete.relocate(100, 0);
        delete.setStyle("-fx-font: 12 arial; -fx-base: rgb(100,0,0); -fx-text-fill: rgb(255,255,255);");

        Button stats = new Button("Stats");
        stats.setPrefSize(90, 30);
        stats.relocate(210, 0);

        p.getChildren().addAll(add, delete, stats);
        getChildren().add(p);
    }
}

getChildren is the same as calling this.getChildren . That line adds p to the children collection of the DVDButtonPane .

its adding "p" to the DVDButtonPane. But if the DVDButtonPane itself is extending from Pane. You could have directly added the buttons to the DVDButtonPane

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM