java - 为什么 getItems 方法不适用于按钮
问题描述
javafx类库其实说ToolBar.getItems()适用于按钮和节点,但是当我在工具栏中添加按钮时,终端不让我编译,说不合适。这里是代码
public void setBoard(){
ToolBar toolbar = new ToolBar();//create an empty tool bar
Button btnnt = new Button ("Next");
Button btnpr = new Button ("Privieous");
Button btnst = new Button ("Start");
Button btnps = new Button ("Pause");
toolbar.getItems().add(btnnt,btnpr,btnst,btnps);//add all buttons
border.setBotton(toolbar);//set bottom border
Label Columnlb = new Label("Enter the weidth");
Label Rowlb = new Label("Enter the height");
TextField column = new TextField();
column.setPreflength(20);
columns = Integer.parseInt(column.getText());
TextField row = new TextField();
rows = Integar.parseInt(row.getText());
Hbox hbox = new Hbox();
Hbox.getItems().add(Columnlb,column,Rowlb,row);
border.setTop(hbox);
}
和错误信息
GOL.java:29: error: no suitable method found for add(Button,Button,Button,Button)
toolbar.getItems().add(btnnt,btnpr,btnst,btnps);//add all buttons
^
method Collection.add(Node) is not applicable
(actual and formal argument lists differ in length)
method List.add(Node) is not applicable
(actual and formal argument lists differ in length)
method List.add(int,Node) is not applicable
(actual and formal argument lists differ in length)
这就是图书馆所说的
getItems
public final ObservableList<Node> getItems()
The items contained in the ToolBar. Typical use case for a ToolBar suggest
that the most common items to place within it are Buttons, ToggleButtons,
and Separators, but you are not restricted to just these, and can insert
any Node. The items added must not be null.
解决方案
推荐阅读
- symfony - 使用 Symfony 序列化器组件时在反序列化期间处理不正确的数据
- java - Gradle:在我自己的任务中从导入的插件调用任务
- software-design - 允许的最大线性独立圈复杂度指南?
- python - Python 正则表达式语句错误
- php - 从 PHP 生成 Postman 预览
- react-native - 如何将响应传递给 react-native RNPickerSelect 功能组件
- filter - GroupBy 函数不在 PowerApps 中显示图库磁贴
- amazon-ec2 - DBeaver 通过 SSH 隧道连接
- php - PHP:编写非 ASCII 字符,如德语变音符号 (öäü)
- azure - 在 Azure DevOps 中查找和删除重复的仪表板