【问题标题】:White rectangle in subscene when creating a label JavaFX创建标签JavaFX时子场景中的白色矩形
【发布时间】:2019-12-19 10:41:51
【问题描述】:

每当我尝试向我的 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);
    }

}

【问题讨论】:

标签: java javafx graphics rendering


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多