[英]Why am I receiving an error when trying to add a Button to a GridPane?
I'm getting an error for grid.add(button, c, r);我收到 grid.add(button, c, r) 的错误; saying "the method add(node, int, int) in the type GridPane is not applicable for the arguments (Button, int, int)".说“GridPane 类型中的方法 add(node, int, int) 不适用于参数 (Button, int, int)”。 This is such a trivial thing but I cannot figure out what's wrong.这是一件微不足道的事情,但我无法弄清楚出了什么问题。 I know it's saying I'm trying to put a Button where a node is supposed to be, but I've looked up examples of buttons being added to gridpanes and they have this exact syntax with no issues.我知道它是说我试图将一个 Button 放在一个节点应该在的位置,但我已经查找了将按钮添加到网格窗格的示例,并且它们具有这种确切的语法,没有任何问题。
Sorry if this has been asked/answered previously, I couldn't find any question that was the same as this.抱歉,如果之前有人问过/回答过这个问题,我找不到与此相同的任何问题。
public class Demo extends Application {
public static void main(String[] args) {
// Nothing
}
@Override
public void start(Stage stage) {
GridPane grid = new GridPane();
grid.setPadding(new Insets(3));
grid.setHgap(10);
grid.setVgap(10);
for (int r = 0; r < 10; r++) {
for (int c = 0; c < 10; c++) {
int number = 10 * r + c;
Button button = new Button();
grid.add(button, c, r);
}
}
stage.show();
}
}
Maybe, check imports to be sure that you are not importing from java.awt library?也许,检查导入以确保您不是从 java.awt 库导入?
import javafx.geometry.Insets;
import javafx.scene.control.Button;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.