2017-04-05 13 views
0

一度に複数の折りたたみ可能なTitledPane(デフォルトのJavaFXアコーディオンではサポートしていない)が必要なので、いくつかのTitledPanesをVBoxに追加しました。これまでのところうまく動作しますが、TitledPanesの幅は実際のVBoxの幅よりも10px小さいことに気付きました。VBoxをTitledPaneで埋める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> 

:CSSファイルを追加し、適応した後 before

は、レイアウトは次のようになります。 after

コード:

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

私の場合、この解決策はうまくいきますが、貧弱な回避策のようです。私はスマートな解決策が必要だと思いますか?事前に

どうもありがとう:)

答えて

1

ペインをステージにリサイズされていますが、のVBoxの幅が1000pxを超えることはできません。 キャプチャのステージの幅は約1010ピクセルです。

あなたはペインを省略することができるはずです。

<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> 

<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の大きさを調整するためには、何らかの理由で上記のパネルを必要とする場合

+0

おかげで、それはそれでした! ;-) – pixelstuermer

0

ありがとう@geh:

シーンにステージをリサイズすることで、 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

関連する問題