2012-03-09 220 views
1

我有一個用於繪製三維對象的Canvas3D類的應用程序。畫布背景默認爲黑色。我想改變它,但我不知道如何。我從互聯網上找到了一段代碼,但它不起作用。這裏是代碼:如何設置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); 

你對這個問題有幫助嗎?

在此先感謝。

回答

3
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); 
+0

非常感謝。我解決了我的問題。 – Hassan 2012-03-10 13:11:17

+0

Welcme。如果你有任何資訊我的答案,請加入或加註。否則,你可以離開這個 – 2012-03-10 13:25:17