Is it possible to have an accordion with more then 1 open pane in JavaFX?
相关问题
- I get an exception when trying to swap elements in
- JFX scale image up and down to parent
- Dragging an undecorated Stage in JavaFX
- JavaFX sample issue
- How to change the font size in ListView in JavaFX?
相关文章
- Low quality icon in taskbar of a Stage. JavaFX
- Loading custom font using JavaFX 8 and css
- Javafx Platform.runLater never running
- JavaFX scrolling table update performance degrades
- Javafx select multiple rows
- Escape from a Number TextField in a JavaFX dialog
- How to merge cells in JavaFX Scene builder?
- Adding view with constructor arguments to a border
No, a JavaFX 2.2 Accordion can only have one open pane at a time.
I created an enhancement request (JDK-8090554 StackedTitledPanes control) for a feature which allows you to open more than one pane in the accordion at a time, however the feature request has currently not been implemented.
In the meantime, you can construct a similar control yourself quite easily by creating multiple TitledPane instances and placing these in a VBox.
If necessary, you can wrap the
VBox
containing your panes in a ScrollPane, so that the contents of all of your expanded panes can be usable if their area overflows the available area.I created a sample solution (icons are linkware from: http://www.fasticon.com).
I had slightly different requirements
Although in my case, I was not able to fulfill all of 3. and test 2., I was able to come up with the following fix:
1) Use a ScrollPane, with a VBox inside, with TitledWindows inside. 2) Make sure your TitledPanes are set to VBox.grow="SOMETIMES" . 3) Add a VBox as the last element and set VBox.vgrow="ALWAYS" - this pushes the TitledPanes up to their minimum size. Everybody else has provided Code examples, if you want to use fxml, or don't want to use Java, just using the elements directly works just as well (generated with SceneBuilder):
4) Although this does get you stacked boxes which expand/contract independently of one another, this doesn't fix the issue where you have boxes which do not resize properly to their contents (if for example you have a List View embedded as in the above example), and so you now have to scroll quite a bit when there is plenty of screen real-estate left. The solution? A bit of Java is required.
To implement this fix, we first bind the TitledPane's
maxHeightProperty()
to the outer VBox'sheightProperty()
:The we bind to each pane's
expandedProperty()
, and dynamically bind and unbind theprefHeighProperty()
:}
If we are shown, we ask to be as large as the VBox, if we aren't shown, we ask to be as small as possible. The benefit of doing things this way is that the layout then automatically calculated the available height based on the number of currently shown TitledPanes - which leads to exactly the behavior that we want.
I go into more detail here:
http://sebastianaudet.com/blog/playing-with-javafx/