2013-03-13 29 views

回答

31

不,一個JavaFX 2.2 Accordion一次只能有一個打開窗格。

我爲一個功能創建了一個增強請求(JDK-8090554 StackedTitledPanes control),該功能允許您一次在手風琴中打開多個窗格,但功能請求目前尚未實現。

與此同時,您可以通過創建多個TitledPane實例並將它們放置在VBox中來輕鬆構建類似的控件。

private VBox createStackedTitledPanes() { 
    final VBox stackedTitledPanes = new VBox(); 
    stackedTitledPanes.getChildren().setAll(
    new TitledPane("Pane 1", contentNode1), 
    new TitledPane("Pane 2", contentNode2), 
    new TitledPane("Pane 3", contentNode3) 
); 
    ((TitledPane) stackedTitledPanes.getChildren().get(0)).setExpanded(true); 

    return stackedTitledPanes; 
} 

如果需要,你可以用含有VBox您的窗格,ScrollPane,因此,如果他們的地區溢出的可用區域所有擴展窗格中的內容可以使用。

我創建了一個sample solution(圖標是鏈接來自:http://www.fasticon.com)。

fishyfishy

+0

您好,感謝您的樣品。這對我來說很有用。 – sight 2013-03-14 10:33:01

+0

功能請求鏈接不起作用了。 – 2015-09-11 18:34:52

+0

是的,JavaFX特定jira問題跟蹤系統已停用。據我所知,來自該系統的問題和功能請求已轉移到官方的JDK問題跟蹤系統,但我不知道如何在該系統中查找或鏈接相關問題。我建議與[第三方ControlsFX庫](http://fxexperience.com/controlsfx/)開發人員聯繫,以查看他們是否有興趣添加StackedTitledPanes控件到此控件的官方JDK功能請求過程他們的圖書館 – jewelsea 2015-09-11 19:13:33

0

我有稍微不同的要求

  1. 手風琴要麼擴大或管理視圖空間嵌入式意見
  2. 整個視圖都可以被放入滾動視圖
  3. 每如果手風琴是固定的尺寸,或者它擴展到內容的大小,如果它不是固定的視圖,那麼盒子完全擴展到整個視圖的大小。

雖然在我的情況,我是不是能夠滿足所有的3和測試2,我能想出以下修正:

1)使用一個ScrollPane,具有垂直框裏面有TitledWindows裏面。 2)確保您的TitledPanes設置爲VBox.grow =「有時」。 3)添加一個VBox作爲最後一個元素並設置VBox.vgrow =「ALWAYS」 - 這會將TitledPanes推到最小尺寸。其他人都提供了代碼示例,如果你想使用FXML,或不想使用Java,只是直接使用作品一樣好(與SceneBuilder生成)的元素:雖然這

<ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"> 
    <content> 
     <VBox fx:id="leftVBox" maxHeight="1.7976931348623157E308" prefHeight="200.0" prefWidth="100.0"> 
      <children> 
       <TitledPane fx:id="titledPanelOne" animated="false" expanded="false" style="-fx-background-color: red;" text="Pane One" VBox.vgrow="SOMETIMES"> 
       <content> 
        <ListView fx:id="listViewOne" maxHeight="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" /> 
       </content> 
       </TitledPane> 
       <TitledPane fx:id="titledPanelTwo" animated="false" expanded="false" style="-fx-background-color: green;" text="Pane Two" VBox.vgrow="SOMETIMES"> 
       <content> 
        <ListView fx:id="listViewTwo" maxHeight="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" /> 
       </content> 
       </TitledPane> 
       <VBox prefHeight="0.0" prefWidth="0.0" VBox.vgrow="ALWAYS" /> 
      </children> 
     </VBox> 
    </content> 
</ScrollPane> 

4)讓你堆疊的盒子彼此獨立展開/收縮,這並不能解決你有盒子不能正確調整其內容的問題(例如,如果你有一個列表視圖嵌入在上面的例子中),並且所以當有大量屏幕房產留下時,您現在必須滾動一下。解決方案?需要一點Java。

要實現此修復程序,我們首先綁定TitledPane的maxHeightProperty()到外垂直框的heightProperty():我們綁定到每個窗格的expandedProperty(),並動態

public class Controller implements Initializable { 
    //... controller code 
    @Override 
    public void initialize(URL location, ResourceBundle resources) { 
    //... 
    variablesViewPane.maxHeightProperty().bind(leftVBox.heightProperty()); 
    historyViewPane.maxHeightProperty().bind(leftVBox.heightProperty()); 
    } 
} 

綁定和取消綁定prefHeighProperty()

private static void bindExpanded(TitledPane pane, ReadOnlyDoubleProperty prop) { 
    pane.expandedProperty().addListener((observable, oldValue, newValue) -> { 
    if(newValue) { 
     pane.prefHeightProperty().bind(prop); 
    } else { 
     pane.prefHeightProperty().unbind(); 
     pane.prefHeightProperty().set(0); 
    } 
    }); 

}

如果我們顯示,我們要求與VBox一樣大,如果我們沒有顯示,我們要求儘可能小。這樣做的好處是,佈局然後根據當前顯示的TitledPanes的數量自動計算可用高度 - 這導致我們想要的行爲。

我進入更詳細的位置:

http://sebastianaudet.com/blog/playing-with-javafx/