如何设置Canvas3D背景色?

如何设置Canvas3D背景色?,canvas,background,java-3d,Canvas,Background,Java 3d,我有一个Canvas3D类的应用程序,用于绘制三维对象。默认情况下,画布背景为黑色。我想改变它,但我不知道怎么做。我从网上找到了一段代码,但它不起作用。代码如下: setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); canvas = new Canvas3D(config); JPanel ce

我有一个Canvas3D类的应用程序,用于绘制三维对象。默认情况下,画布背景为黑色。我想改变它,但我不知道怎么做。我从网上找到了一段代码,但它不起作用。代码如下:

        setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    canvas = new Canvas3D(config);


    JPanel centerPanel = new JPanel(new GridLayout(1, 1));
    centerPanel.setBorder(BorderFactory.createLineBorder(Color.black));
    centerPanel.add(canvas);

    universe = new SimpleUniverse(canvas);

    Background newBk = new Background(new Color3f(Color.WHITE)); 
    newBk.setApplicationBounds(new BoundingSphere(new Point3d(0f,0f,0f), 100)); 
    canvas.getGraphicsContext3D().setBackground(newBk);
你能帮我解决这个问题吗


提前谢谢。

欢迎光临。如果您收到我的回复,请接受或投票。否则你可以离开这里
Background background = new Background(new Color3f(1f,0,0));
BoundingSphere sphere = new BoundingSphere(new Point3d(0,0,0), 100000);
background.setApplicationBounds(sphere);
viewingPlatform.addChild(background);