首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HBox没有出现

HBox没有出现
EN

Stack Overflow用户
提问于 2015-11-28 02:27:02
回答 1查看 776关注 0票数 0

因此,我似乎无法使HBox出现在我的应用程序中。按钮会出现,但是HBox不会出现。有人能告诉我我做错了什么吗?

代码语言:javascript
复制
package cyanlauncher;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;


public class Main extends Application {
    private int numApps = 0;
    private float btnSize = 48;
    private float btnSpacing = 12;
    @Override
    public void start(Stage primaryStage) {
            primaryStage.initStyle(StageStyle.TRANSPARENT);
            primaryStage.setTitle("CyanLauncher");

            Button quitBtn = new Button();

            Pane  root = new Pane();
            root.getChildren().add(addHBox());

            quitBtn.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("./../data/exit.png"))));
            quitBtn.setLayoutX(10 + ((btnSize + btnSpacing) * numApps));
            quitBtn.setLayoutY(7);
            quitBtn.setPadding(new Insets(0,0,0,0));
            quitBtn.setPrefSize(btnSize, btnSize);
            quitBtn.setOnAction(new EventHandler<ActionEvent>(){

                @Override
                public void handle(ActionEvent event){
                    System.exit(0);
                }

            });

            root.getChildren().add(quitBtn);


            Scene scene = new Scene(root,64,64);


            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            scene.setFill(null);

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

    public HBox addHBox() {
        HBox hbox = new HBox();
        hbox.setPrefSize(64, 64);
        hbox.setLayoutX(10);
        hbox.setLayoutY(7);  
        return hbox;
    }

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

这是我的CSS:

代码语言:javascript
复制
/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
.root {
     -fx-background-color: rgba(0,255,0,1);
}

.button {
     -fx-background-color: rgba(0,0,255,1);
}

.hbox {
    -fx-background-color: rgba(255,0,0,1);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-28 02:35:33

默认情况下,HBox没有样式类(参见文档)。因此,您需要在(非常糟糕的名称) addHBox()方法中执行addHBox()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33967035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档