首页 > 解决方案 > 创建标签JavaFX时子场景中的白色矩形

问题描述

每当我尝试向我的 JavaFX 应用程序添加标签时,该应用程序使用了一个在其中绘制 3D 形状的 SubScene,我在 SubScene 中得到一个白色矩形。我什至不必对标签做任何事情,它总是这样做。

没有标签的舞台图片

带有标签的舞台图片

我已经提供了一些带有标签的代码,尽管我找不到任何问题。

package UI;

import Cargo.CargoSpace;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.image.Image;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.scene.control.Label;

public class MainApp extends Application {

    @Override
    public void start(Stage stage) {

        //Set Initial stage settings
        stage.setTitle("Pentominoes - Group X");
        stage.getIcons().add(new Image(Settings.pathToTitleBarImage));
        stage.setResizable(false);
        stage.setAlwaysOnTop(true);

        //Main scene of the stage
        HBox scenePane = new HBox();
        scenePane.setPadding(Settings.mainScenePadding);

        //SubScene containing the cargo space
        CargoSubScene cargoSubScene = new CargoSubScene(new CargoSpace(Settings.cargoSpaceDims[0],Settings.cargoSpaceDims[1],Settings.cargoSpaceDims[2], 2));
        scenePane.getChildren().add(cargoSubScene);

        //SubScene containing the selections in the main menu
        GridPane selectionLayout = new GridPane();
        scenePane.getChildren().add(selectionLayout);

        Label title = new Label("Pentominoes Phase 3");
        selectionLayout.add(title, 0, 0);

        //Adding main scene to the stage
        Scene cargoScene = new Scene(scenePane, Settings.mainSceneSize[0], Settings.mainSceneSize[1]);
        stage.setScene(cargoScene);

        //Displaying the stage
        stage.show();

    }

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

}

标签: javajavafxgraphicsrendering

解决方案


您可以通过将 2D 元素和 3D 元素放在单独的组中并将这两个组添加到超级组来解决它。


推荐阅读