java - 创建标签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);
}
}
解决方案
您可以通过将 2D 元素和 3D 元素放在单独的组中并将这两个组添加到超级组来解决它。
推荐阅读
- postman - 使用 Postman 进行负面测试
- azure-devops - 如果部署后门检查失败,部署是否会回滚到上次部署的构建?
- c++ - 如何将 const 添加到 decltype(...) typedef?
- python - 数据框在满足条件时选择连续跨度
- c# - 提取 n 位并从 Int32 创建 int
- sql - 从Oracle中的表中获取日期过滤器?
- c# - RepoDB - 忽略属性
- mysql - SQL 查询:奇怪的 SUM 行为
- node.js - nodeJS和expressJS中的Bootstrap问题
- ruby-on-rails - 如何替换rubyracer javascript运行时