In javaFx, Why do we need to call “getChildren()” when we add an element to a window?

后端 未结 3 1201
不思量自难忘°
不思量自难忘° 2020-12-31 17:26

For example, when we add a new button to a pane, we need to write the following code:

 StackPane pane = new StackPane();
 pane.getChildren().add(new Button(\         


        
3条回答
  •  清酒与你
    2020-12-31 18:01

    Instead of providing Individual methods for different operations on children like add(),addAll(), remove(), removeAll() .. etc.

    It is simple to provide well known collection so that every operation supported by List are available and it will make the class simple and less verbose. In this case javafx.scene.layout.Pane class stores the children in ObservableList which is a List

提交回复
热议问题