2015-10-20 31 views
0

我有一個事件處理程序,它有一個視圖實例(javafx Scene)。把一個javafx按鈕實例放在「移動」節點中

下面是場景的代碼:

public class GameMenuScene { 

    private final Button btnArcade; 
    private final Button btnTraining; 
    private final Button btnReplay; 

    private final VBox mainMenuBox; 
    private Scene mainMenuScene; 

    public GameMenuScene() { 
     btnArcade = new Button("Arcade"); 
     btnTraining = new Button("Training"); 
     btnReplay = new Button("Replay"); 

     mainMenuBox = new VBox(4); 
     mainMenuBox.getChildren().addAll(btnArcade, btnTraining, btnReplay); 

     mainMenuScene = new Scene(mainMenuBox, 300, 300); 
    } 

    public Scene getGameMenuScene() { 
     return mainMenuScene; 
    } 

    public VBox getGameMenuSortcut() { 
     return mainMenuBox; 
    } 

在我的應用程序類,我先請getGameMenuScene();mainMenuScene得到正確顯示。

問題是當我從其他EventHandler調用getGameMenuSortcut();時,菜單看起來是空的,但在調試中我可以看到按鈕在VBox中。 當我使用getGameMenuSortcut()時,它們爲什麼不出現在VBox中?在另一種觀點?

下面是其他事件處理程序的示例:

public class EV { 
    private final Scene EVview; 

    private GameMenuScene sc; 
    private VBox menu; 

    public EV() { 
     menu.getChildren.add(new Label("Menu")); 
     EVview = new Scene(mainMenuBox, 300, 300); 
     addMenu(); //This add a menu with the 3 buttons, but they do not get displayed. 
    } 

    public void addMenu() { 
     menu.getChildren.add(sc.getGameMenuSortcut()); 
    } 
} 
+0

您提供的信息不完整。如果答案不夠,請提供[MCVE](http://stackoverflow.com/help/mcve)。 – Roland

回答

0

你加入mainMenuBox不同的場景。

+0

是的,那是我想要做的,或者至少是按鈕。他們在2個不同的場景中,但在第二個場景中,他們沒有出現,有沒有辦法在2個不同的場景中擁有相同的VBox或類似於javafx中的VBox? – Benoit