2013-03-13 83 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/