Button类的对象未添加到布局容器对象(HBox、VBox等)。是否没有默认构造函数可接受Button对象?
创始人
2025-01-10 04:30:04
0

这可能是因为您忘记将Button对象添加到布局对象中。您可以使用以下代码示例创建一个HBox对象并将其中两个Button对象添加到其中:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        
        // 创建两个Button对象
        Button button1 = new Button("Button 1");
        Button button2 = new Button("Button 2");

        // 创建一个HBox对象,将button1和button2添加到其中
        HBox hbox = new HBox(button1, button2);

        // 创建一个Scene对象并将HBox对象添加到其中
        Scene scene = new Scene(hbox, 300, 200);

        primaryStage.setScene(scene);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

请注意,HBox类具有几个构造函数,但是没有接受Button对象的构造函数。相反,您可以在HBox对象中使用add()方法手动将Button对象添加到其中。

相关内容

热门资讯

透视线上!wepoker安装教... 透视线上!wepoker安装教程,wepoker底牌透视脚本,实用技巧(有挂方法)1、操作简单,无需...
透视私人局!wepoker祈福... 透视私人局!wepoker祈福有用吗,wepokerplus外挂(透视)总结教程(有挂详情)1、进入...
透视工具!wepoker辅助是... 透视工具!wepoker辅助是真的假的,wepoker软件靠谱么(透视)2025新版教程(有挂黑科技...
透视新版!红龙poker辅助,... 透视新版!红龙poker辅助,hhpoker买挂,攻略教程(有挂技巧)1、打开软件启动之后找到中间准...
透视安卓版!wepoker模拟... 透视安卓版!wepoker模拟器哪个好用,wepoker破解是真的还是假的(透视)解密教程(有挂介绍...
透视存在!wepoker私人局... 透视存在!wepoker私人局透视,aapoker怎么设置抽水,必备教程(有挂秘籍)1、该软件可以轻...
透视好牌!wepoker有插件... 透视好牌!wepoker有插件吗,wepoker游戏的安装教程(透视)必赢教程(有挂介绍)在进入we...
透视工具!hhpoker辅助挂... 透视工具!hhpoker辅助挂下载,wepoker透视有没有,2025教程(有挂秘笈);hhpoke...
透视规律!wepoker插件辅... 透视规律!wepoker插件辅助,wepoker辅助器免费(透视)透牌教程(有挂工具)1、上手简单,...
透视科技!德扑HHpoker有... 透视科技!德扑HHpoker有挂吗,wepoker私人局可以透视,普及教程(有挂规律)在进入wepo...