2016-07-11 51 views
1

所以我有這個.fxml:JavaFX的按鈕消失的時候.fxml在場景根

<StackPane fx:controller="controller.MainController" xmlns:fx="http://javafx.com/fxml"> 

    <Pane fx:id="aDrawPane" prefHeight="8000" prefWidth="10000" minWidth="10000" minHeight="8000"> 

    </Pane> 
    <BorderPane fx:id="aBorderPane"> 
     <top> 
      <VBox> 
       <ToolBar fx:id="aToolBar" orientation="HORIZONTAL"> 
        <HBox fx:id="umlBox"> 
         <Button text="Create" fx:id="createBtn"/> 
         <Button text="Package" fx:id="packageBtn"/> 
         <Button text="Edge" fx:id="edgeBtn"/> 
         <Button text="Draw" fx:id="drawBtn"/> 
        </HBox> 
        <HBox fx:id="utilBox"> 
         <Button text="Select" fx:id="selectBtn"/> 
         <Button text="Move" fx:id="moveBtn"/> 
        </HBox> 
        <HBox fx:id="undoBox"> 
         <Button text="Delete" fx:id="deleteBtn"/> 
         <Button text="Undo" fx:id="undoBtn"/> 
         <Button text="Redo" fx:id="redoBtn"/> 
        </HBox> 
        <HBox fx:id="recognizeBox"> 
         <Button text="Recognize" fx:id="recognizeBtn"/> 
        </HBox> 
       </ToolBar> 
      </VBox> 
     </top> 
     <bottom> 
      <ToolBar> 
       <Pane HBox.hgrow="ALWAYS" /> 
       <VBox alignment="CENTER"> 
        <Slider fx:id="zoomSlider" min="10" max="200" value="100"/> 
        <Label text="Zoom"/> 
       </VBox> 
       <Pane HBox.hgrow="ALWAYS" /> 
      </ToolBar> 
     </bottom> 
    </BorderPane> 

    <stylesheets> 
     <URL value="@main.css" /> 
    </stylesheets> 
</StackPane> 

而我的應用程序啓動器類:

public class Launcher extends Application { 

    public void start(Stage stage) throws IOException { 
     BorderPane tabView = null; 
     FXMLLoader loader; 

     StackPane canvasView = null; 
     try { 
      loader = new FXMLLoader(getClass().getClassLoader().getResource("view.fxml")); 
      canvasView = (StackPane) loader.load(); 
     } catch (IOException e) { 
      System.out.println(e.getMessage()); 
     } 

     Scene scene = new Scene(canvasView, 1000, 800); 

     stage.setScene(scene); 
     stage.show(); 
    } 
} 

有了這個頂部工具欄中的按鈕是可見的和工作以及底部的滑塊。

但是,如果我的代碼改變爲以下:

Group root = new Group(); 
root.getChildren().add(canvasView); 
Scene scene = new Scene(root, 1000, 800); 

頂部工具欄是可見的,但按鈕是不可見的和不可點擊和底部工具欄是完全disappeard(和第一窗格「aDrawPane 「按預期工作)。 當我想將view.fxml放在Tab中時,我遇到了這個問題。 爲什麼會發生這種情況,我怎樣才能使工具欄和按鈕再次可見?

+0

你有沒有任何理由使用一個'Group'而不是由laoder作爲根返回的'StackPane'? – DVarga

回答

0

原因是一個團體沒有調整其子女的大小,而是將他們按照他們喜歡的大小呈現。

的FXML指出,面板應該是

prefHeight="8000" prefWidth="10000" minWidth="10000" 

,這是你得到什麼。

+0

你是對的!感謝您的幫助。 – imarcus