[英]What happens when you call getChildren on it's own?
我對Java相對較新,尤其是Javafx和GUI。 我一直在編寫此代碼,但是在理解VERY LAST LINE正在做什么時遇到了一些麻煩。 我知道倒數第二行是將所有組件添加到容器“ p”中,但是調用不帶容器的getChildren()會發生什么。 無論如何,我們會提供任何幫助。
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
與調用this.getChildren
相同。 該行將p
添加到DVDButtonPane
的children集合中。
將其“ p”添加到DVDButtonPane。 但是,如果DVDButtonPane本身是從Pane擴展的。 您可以直接將按鈕添加到DVDButtonPane
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.