2017-04-05 44 views
0

因为我需要一次有多个可折叠的TitledPanes(默认的JavaFX Accordion不支持),所以我在VBox中添加了一些TitledPanes。到目前为止,这工作正常,但我意识到TitledPanes的宽度比实际的VBox的宽度小10px。带有标题栏的VBox的JavaFX填充

继FXML代码:

<Pane prefHeight="700.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.71" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
     <VBox prefHeight="700.0" prefWidth="1000.0"> 
      <children> 
       <TitledPane animated="false" text="Pane 1"> 
        <content> 
         <AnchorPane prefHeight="300.0" /> 
        </content> 
       </TitledPane> 
       <TitledPane animated="false" text="Pane 2"> 
        <content> 
         <AnchorPane prefHeight="300.0" /> 
        </content> 
       </TitledPane> 
      </children> 
     </VBox> 
    </children> 
</Pane> 

将会产生本(见右侧的间隙): before

加入和适应一个CSS文件后,布局看起来是这样的: after

该css代码:

VBox { 
    -fx-padding: 0 -11 0 -1; 
} 

对我来说,这个解决方案工作正常,但它看起来像一个糟糕的解决方法。我想那里需要更聪明的解决方案?!

感谢很多提前:)

回答

1

窗格调整大小与舞台,但垂直框的宽度不超过1000像素。 捕捉阶段的宽度大约为1010px。

你应该能够与窗格分配:

<VBox xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
     <TitledPane animated="false" text="Pane 1"> 
      <content> 
       <AnchorPane prefHeight="300.0" /> 
      </content> 
     </TitledPane> 
     <TitledPane animated="false" text="Pane 2"> 
      <content> 
       <AnchorPane prefHeight="300.0" /> 
      </content> 
     </TitledPane> 
    </children> 
</VBox> 

或者使用AnchorPane调整VBOX的大小,如果由于某种原因需要上述面板:

<AnchorPane xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
     <VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> 
      <children> 
       <TitledPane animated="false" text="Pane 1"> 
        <content> 
         <AnchorPane prefHeight="300.0" /> 
        </content> 
       </TitledPane> 
       <TitledPane animated="false" text="Pane 2"> 
        <content> 
         <AnchorPane prefHeight="300.0" /> 
        </content> 
       </TitledPane> 
      </children> 
     </VBox> 
    </children> 
</AnchorPane> 
+0

谢谢,原来如此! ;-) – pixelstuermer

0

谢谢@geh:

调整舞台到场景解决了问题,没有nee一个css调整的d:

@Override 
public void start(Stage stage) throws Exception { 
    Pane root = (Pane) FXMLLoader.load(getClass().getResource("root.fxml")); 
    Scene scene = new Scene(root); 
    stage.setScene(scene); 
    stage.setResizable(false); 
    // the following solved it 
    stage.sizeToScene(); 
    stage.setTitle("JavaFx Test"); 
    stage.show(); 
} 

after after