java Java中使用的方法“.getChildren()”是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43491401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 07:28:37  来源:igfitidea点击:

What is the method ".getChildren()" used for in Java?

javajavafxmethods

提问by Olo Olo

For example if I were to add a line of code such as-

例如,如果我要添加一行代码,例如-

hbox.getChildren().add(calculateButton);

what significance does .getChildren hold and what happens if it not used in a program?

.getChildren 有什么意义?如果不在程序中使用它会怎样?

回答by Deepesh Choudhary

getChildrenmethod is used to get the children components(such as checkboxes, buttons etc) in a container.

getChildren方法用于获取容器中的子组件(例如复选框、按钮等)。

In your case, hBoxis a container which can contain buttons, spinners etc. So getChildrenlists the current components in hBox.

在您的情况下,hBox是一个可以包含按钮、微调器等的容器。所以getChildren列出了 hBox 中的当前组件。

It is basically a list of components currently present in the container. By using add()you are adding a new component in that list.

它基本上是容器中当前存在的组件列表。通过使用,add()您将在该列表中添加一个新组件。