简体   繁体   English

为什么在尝试将 Button 添加到 GridPane 时会收到错误消息?

[英]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.

相关问题 为什么当我按下“小程序”按钮时收到“抽象类”错误? - Why am I receiving an Abstract Class error when I press the Applet button? 为什么在尝试通过URL“jdbc:h2:test”创建数据库时收到错误 - Why am I receiving an error when trying to create the database by the URL of “jdbc:h2:test” 为什么我在尝试检查磨机时收到 ArrayIndexOutofBoundsException? - Why am I receiving an ArrayIndexOutofBoundsException when trying to check for mills? 为什么我在定义时收到 IdClass 未定义错误? - Why am I receiving an IdClass not defined error when it is defined? 我正在尝试访问页面,但收到 500 错误 - I am trying to reach page and I am receiving 500 error 为什么我收到此sql错误? - Why I am receiving this sql error? 为什么我会收到堆栈溢出错误? - Why am I receiving a Stack overflow error? 为什么在尝试实现 ViewModel 时出现此错误? - Why am i getting this error when trying to Implement ViewModel? 为什么在尝试与我的服务器通信时出现此错误? - Why am i getting this error when trying to communicate with my server? 为什么在尝试将 tUSDT 添加到特定账户时出现“处理交易请求时出错:内在气体太低”错误? - Why am I getting "Error processing transaction request: intrinsic gas too low" error when trying to add tUSDT to a particular account?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM