2017-05-02 30 views
0

點擊爲我的個人項目我的編程課,並在稍後發佈我來到一個問題,我不期望遇到。當我點擊一個菜單按鈕項時,我想要在窗格中顯示一個3d形狀,我在互聯網上搜索,搜索它以50-100種不同的方式(或一個很好的粗略估計),但沒有發現任何東西。我一直百思不得其解如何顯示單擊菜單項時的3D形狀上,這裏是我的源代碼(FXML):我如何顯示一個3d形狀按鈕在javafx

<MenuButton layoutX="14.0" layoutY="92.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="72.0" text="shapes"> 
    <items> 
     <MenuItem mnemonicParsing="false" onAction="#itemcircle" text="circle" /> 
     <MenuItem mnemonicParsing="false" onAction="#itemsquare" text="square/surfice" /> 
     <MenuItem mnemonicParsing="false" onAction="#itemcube" text="cube" /> 
     <MenuItem mnemonicParsing="false" onAction="#itemsphere" text="sphere" /> 
     <MenuItem mnemonicParsing="false" onAction="#itemcyllinder" text="cyllinder" /> 
    </items> 
    </MenuButton> 

我的其他源代碼示例(JavaFX的):

public void itemcyllinder(ActionEvent cyllinderspawn) 
{ 
    Cylinder cylinder = new Cylinder(40, 120); 
    cylinder.setTranslateX(500); 
    cylinder.setTranslateY(-25); 
    cylinder.setTranslateZ(600); 
} 

那麼我如何使用javafx/fxml顯示三維形狀/對象?

編輯:我忘了,更不用說我希望它顯示爲一個窗格中我的場景

+0

您是否嘗試過在按鈕上添加一個點擊事件處理程序並更改點擊'Cylinder'的可見性? – Oswald

+0

不過是生病的嘗試。 – chucklesdeclown

+0

也許看看在「如何創建自定義」的答案中定義的[模型查看器](http://stackoverflow.com/questions/19459012/how-to-create-custom-3d-model-in-javafx-8) JavaFX 8中的3D模型?「這不完全是你要求的,但可以提供一些關於如何實現你想要的想法。 – jewelsea

回答

0

我找到了答案,這是所有我需要做的與氣缸:

public void itemcyllinder(ActionEvent cyllinderspawn) 
{ 
    Cylinder cylinder = new Cylinder(40, 120); 
    cylinder.setTranslateX(368.0); 
    cylinder.setTranslateY(311.0); 
    whereitgoes.getChildren().add(cylinder); 
} 

我打電話給我的窗格whereitgoes,然後我剛纔用的getChildren有在窗格中我把它叫做在氣缸顯示器去一個菜單按鈕項目點擊(對不起,我不能給一個圖片的例子)

0

我還沒有嘗試過,但我會嘗試在SubScene創建一個3D場景,並設置爲菜單項的graphic property

編輯:以爲你想將3D場景設置爲菜單項的圖形。無論如何,要混合2D和3D,您需要創建SubScenes。

+0

你能否詳細說明一下,可能還有一個示例代碼? – chucklesdeclown

+0

感謝您的回答,但我發現它 – chucklesdeclown

相關問題