我知道在手风琴中不可能打开多个标题窗格。因此,我尝试使用titledPanes和VBox实现逻辑。我要实现的是让每个有标题的窗格在展开后占据VBox的全部高度。
它“正常”运行,但是播放动画时遇到了麻烦。这就是我所拥有的(假设我只有2个标题为“ Panes”):
main.fxml:
<HBox fx:id="main">
<children>
<VBox HBox.hgrow="ALWAYS">
<children>
<TitledPane onMouseClicked="#expandTitle" fx:id="pane1" VBox.vgrow="ALWAYS">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane onMouseClicked="#expandTitle" fx:id="pane2" expanded="false" VBox.vgrow="ALWAYS">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
</children>
</VBox>
</children></HBox>
Controller.java:
public class Controller {
@FXML
private javafx.scene.layout.HBox main;
@FXML
private javafx.scene.control.TitledPane pane1;
@FXML
private javafx.scene.control.TitledPane pane2;
@FXML
private void expandTitle(MouseEvent evt){
TitledPane clickTarget = (TitledPane) evt.getSource();
TitledPane otherTarget = clickTarget == pane1 ? pane2 : pane1;
otherTarget.setExpanded(!clickTarget.expandedProperty().getValue());
if(otherTarget.expandedProperty().getValue()){
otherTarget.setMaxHeight(main.getHeight());
clickTarget.setMaxHeight(0);
} else {
clickTarget.setMaxHeight(main.getHeight());
otherTarget.setMaxHeight(0);
}
}
}
我尝试了setMaxHeight
,setPrefHeight
,它们都具有相同的结果。这是它的外观与我的期望: