This discussion is archived
12 Replies Latest reply: Jan 30, 2012 7:35 AM by 909362 RSS

TitledPane in a VBox ... TitledPane ignores maxSize

909362 Newbie
Currently Being Moderated
Hi,

I want to use a VBox instead of an Accordion, so i can have more TitledPanes expanded than one.
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>

<VBox xmlns:fx="http://javafx.com/fxml">
     <children>
          <TitledPane VBox.vgrow="ALWAYS">
               <text>Navigation</text>
               <content>
                    <TreeView showRoot="false" >
                         <root>
                              <TreeItem value="Documents">
                                   <children>
                                        <TreeItem value="Item1" />
                                   </children>
                              </TreeItem>
                         </root>
                    </TreeView>
               </content>
          </TitledPane>
          <TitledPane  VBox.vgrow="ALWAYS">
               <text>Navigation</text>
               <content>
                    <TabPane tabClosingPolicy="UNAVAILABLE">
                         <tabs>
                              <Tab> 
                                   <content>
                                        <ListView/> 
                                   </content>
                                   <text>tab1</text>
                              </Tab>
                              <Tab> 
                                   <content>
                                        <ListView/> 
                                   </content>
                                   <text>tab2</text>
                              </Tab>
                         </tabs>
                    </TabPane>
               </content>
          </TitledPane>
     </children>
</VBox>
The strange thing is, that the TitledPanes wont resize correctly ... Its just working if I remove the VBox.vgrow ... but than the TitledPanes wont resize over a maximum Height, even if I set Double.Max_Value as maxHeight.

Anyone has a Idea how to manage these TitledPanes in a VBox?
  • 1. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    jsmith Guru
    Currently Being Moderated
    I had exactly the same control in an app I created.

    I (think) a similar control is also used in the SceneBuilder and in this talk from on JavaFX layout from Amy Fowler (http://www.parleys.com/#st=5&id=2734&sl=0)
    Adding such a control e.g. StackedTitledPanes to the jfxtras project (http://code.google.com/p/jfxtras/) or open-jfx (http://openjdk.java.net/projects/openjfx/) would be a good idea.

    My control implementation has exactly the same issue and (without spending a bit of time on it) I wasn't sure if it was a bug in my code or JavaFX.
    It was one of the first layout tasks I tried in JavaFX2, so I didn't really know what I was doing at the time.
    I can't remember if I set maxSize on the VBox or not, but perhaps I did.
    I do remember that I could not get the control to work as I wished.

    Take at look at Amy's layout talk in the demo section about two thirds through, maybe there will be some pointers there on how to get the effect you want.
  • 2. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    909362 Newbie
    Currently Being Moderated
    Hi,

    thanks for the links ... i got one step closer to the solution!
    In this document: http://docs.oracle.com/javafx/2.0/ui_controls/accordion-titledpane.htm is the comment:
    The titled pane is resized to accommodate the preferred size of its content.
    So I added prefSize to the content node of my TitledPane:
    <TitledPane VBox.vgrow="ALWAYS">
         <text>Navigation</text>
         <content prefHeight="1000">
              ...
         </content>
    </TitledPane>
    I used 1000, since higher values (like Double.MAX_Value) had an bad impact on the collapsing animation.

    Now the TitledPanes resize correctly. Now there is just a strange behavior, when all TitledPanes are collpsed.
    They dont align all at top or bottom, they are centered as you can see in the following image:
    http://img688.imageshack.us/img688/5192/titledpanecollapsed.jpg
    A alignment="top_center" on the VBox wont do the trick :(


    Another "nice to have", would be, that the panes are resizeable like in an SplitPane.
    Any ideas?
    jsmith wrote:
    Adding such a control e.g. StackedTitledPanes to the jfxtras project (http://code.google.com/p/jfxtras/) or open-jfx (http://openjdk.java.net/projects/openjfx/) would be a good idea.
    PS: Yes it would be really nice to have such a standard control! :)

    Edited by: BurnedToast on 26.01.2012 02:39
  • 3. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    jsmith Guru
    Currently Being Moderated
    Looking at the ugly stacked titledpane code I wrote while learning JavaFX (http://code.google.com/p/willow-browser/source/browse/src/main/java/org/jewelsea/willow/SideBar.java), I can see that the way I handled this was to create a bottom spacer which pushes all of the stacked title panes together at the top of the sidebar.
    // layout holder for the sidebar.
    final VBox bar = new VBox();
    
    ....
    // create a bunch of titlepanes.
    ....
    
    // place a spacer in the sidebar which will push all of the titled panes up.
    final VBox spacer = new VBox();
    spacer.getStyleClass().add("sidebar-background");
    VBox.setVgrow(spacer, Priority.ALWAYS);
    
    // put the panes inside the sidebar.
    bar.getChildren().addAll(navPanel, devPanel, demoPanel, benchPanel, spacer);
  • 4. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    909362 Newbie
    Currently Being Moderated
    Wow,
    it works very well! Thanks a lot!

    Now I just miss a SplitPane-like divider.
  • 5. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    909362 Newbie
    Currently Being Moderated
    Hmm~,

    I figured out a little problem with the setting of "prefHeight", now Iam not able to add a ScrollPane to the content of the TitledPane.
    If I do, the ScrollBars wont appear (I think, they will just appear if the content will be bigger than 1000).

    Any Ideas?
  • 6. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    909362 Newbie
    Currently Being Moderated
    I had to post this text, since i wanted to set this Thread back to "not answered":
    The fix with prefHeight caused problems with ScrollPanes
  • 7. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    jsmith Guru
    Currently Being Moderated
    I created http://javafx-jira.kenai.com/browse/RT-19248 for you Toast
  • 8. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    jsmith Guru
    Currently Being Moderated
    Hi BurnedToast, I suggest you download and use the latest 2.1b10+ build of JavaFX http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html as I found the behaviour of TitledPanes inside a VBox has changed. In particular the stacked TitledPanes now appear to respect the maxSize setting of the VBox when you open them (which they seemed to be disregarding previously).
  • 9. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    swpalmer Newbie
    Currently Being Moderated
    Is there a way to get the content inside the TitledPane to resize to the available space?

    I have a couple TitledPanes in a VBox and when both of them are expanded I want the content to share the available space. When only one is expanded I want it to expand to make use of the extra space available. In general the use of the preferred size of the content is not what I want. I want the content to be adjusted based on it's minimum and maximum size.
    I'm not sure if that is clear.. but I think it is also related to the issue of fitting a scroll pane inside the TitledPane.
    My actual content in the TitledPane is another VBox that contains a small HBox with a Label and a couple controls and then a TreeView beneath that. I see that the default size for an empty TreeView is huge! I would like it to adjust to the available space and have a scroll bar.

    Any hints would be appreciated.
  • 10. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    909362 Newbie
    Currently Being Moderated
    In before: thanks for the JIRA-Entry, I will watch it! :)

    In build 10 you are not allowed to set maxWidth and prefWidth in the content-node of the TitledPane anymore.
    Like that:
    <VBox fx:id="sidebar" fx:controller="de.ibees.erp.offline.gui.main.SidebarController" xmlns:fx="http://javafx.com/fxml">
         <children>
              <TitledPane fx:id="navigation">
                   <text>Navigation</text>
                   <content prefHeight="1000">
                        <fx:include source="navigation.fxml"/>
                   </content>
              </TitledPane>
              ...
         </children>
    </VBox>
    So the little "fix" above wont work anymore.
    Now it seems like, the TitledPane will resize with the needed space of its content. So my components should try to get as much height as possible.
    So I tryed to set the minHeight property of my TitledPane-content-root-node (what a word ^^) to a high Value like Double.MAX_VALUE.
    <VBox fx:id="sidebar" fx:controller="de.ibees.erp.offline.gui.main.SidebarController" xmlns:fx="http://javafx.com/fxml">
         <children>
              <TitledPane fx:id="navigation">
                   <text>Navigation</text>
                   <content>
                        <StackPane  minHeight="$MAX_DOUBLE">
                             <children>
                                  <fx:include source="navigation.fxml"/>
                             </children>
                        </StackPane>
                   </content>
              </TitledPane>
              ...
         </children>
    </VBox>
    But this will result in a Freeze or a not starting application ... so I tryed a lower value like 2000 and I got the same behavior like with the older "fix".
    And again the scrollbars wont appear ... apparently because of the minHeight-value, since a "normal" TitledPane has build-in scrollbars (as I discovered :) )

    Anyone have some other ideas how to "strech" the content in the height?

    @swpalmer:
    I think its exactly the same problem you have ... currently we just found the shown solutions.
    For a real world application its maybe currently the best solution to use the Accordion and disclaim the use of multiple expanded TitledPanes, because it seems like there is "something going on" with the TitledPanes :).

    Maybe you should also try the build 10, because its seems to use the min- and maxSize-properties.
  • 11. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    swpalmer Newbie
    Currently Being Moderated
    "since a "normal" TitledPane has build-in scrollbars"

    Huh? When do you see those? I just see the bottom of my content clipped off with no scroll bars.
  • 12. Re: TitledPane in a VBox ... TitledPane ignores maxSize
    909362 Newbie
    Currently Being Moderated
    Sorry my mistake ... i checked it again ... I was wrong! I was using a TreeView inside my TitledPane, that had built in scrollbars!

    But they wont appear in the VBox-Layout ... because of the prefHeight/minHeight-Values ... I just see them in the Accordion!

    Edited by: BurnedToast on 30.01.2012 16:33

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points