This discussion is archived
3 Replies Latest reply: Jul 18, 2012 10:49 AM by 949137 RSS

FXML SplitPane > TitledPane > ScrollPane > AnchorPane > ListView

949137 Newbie
Currently Being Moderated
I have the following structure in FXML to meet the following requirements
1. The two panes of the split pane must be realizable, I have accomplished this by making sure the children of the splitpane have a prefHeight large enough that if the divider was all the way up or down the appropriate pane would be fully visible.
2. Each pane inside the split pane needs a title that is collapsible, the titledpane works nicely for this
3. The three listviews must scroll together, I attempted to accomplish this with the scrollpane. I ended up having to bind the onScroll for each cell to the vValue of the scrollpane (not perfect but manageable).

My problem is that the ListViews maintain a minimum set of rows and you are always allowed to scroll even if those rows are empty.
Basically I want to have the scrollpane scrollbar appear where there is too much data to show in the size allowed by the splitpane.

Am I stuck programmatically adjusting the preHeight of my child controls to make this happen, or am I missing some property that will make this work automagically?
    
<SplitPane fx:id="unschdSplitPane" dividerPositions="0.50" focusTraversable="true" layoutX="0.0" layoutY="32.0" orientation="VERTICAL" prefHeight="521.0" prefWidth="312.0">
      <items>
        <TitledPane fx:id="unscheduledTitlePane" animated="false" text="Unscheduled Flights">
          <content>
            <ScrollPane fx:id="unschdScrollPane" hbarPolicy="NEVER" vbarPolicy="AS_NEEDED" prefHeight="509.0" prefWidth="306.0">
              <content>
                <AnchorPane fx:id="unschdAnchor">
                  <children> 
                    <ListView fx:id="unschdLeftListView" layoutX="2.0" prefHeight="509.0" prefWidth="95.0" maxWidth="95.0" />
                    <ListView fx:id="unschdMidListView" layoutX="99.0" prefHeight="509.0" prefWidth="95.0" maxWidth="95.0" />
                    <ListView fx:id="unschdRightListView" layoutX="196.0" prefHeight="509.0" prefWidth="95.0" maxWidth="95.0" />
                  </children>
                </AnchorPane>
              </content>
            </ScrollPane>
          </content>
        </TitledPane>
        <TitledPane fx:id="scheduledTitlePane" animated="false" text="Scheduled Flights">
          <content>
            <TableView fx:id="scheduledTableView" prefHeight="509.0" prefWidth="306.0" />
          </content>
        </TitledPane>
      </items>
    </SplitPane>
  • 1. Re: FXML SplitPane > TitledPane > ScrollPane > AnchorPane > ListView
    jsmith Guru
    Currently Being Moderated
    Don't place the ListViews in an AnchorPane, instead put them in a layout which resizes (for example HBox).
    Don't set the preferred height of the ListViews at all, let the resizable pane resize it to any height it wants and just set the preferred height on the resizable pane enclosing all of your ListViews.
    <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="574.0" prefWidth="628.0" xmlns:fx="http://javafx.com/fxml">
      <children>
        <HBox layoutX="58.0" layoutY="53.0" prefHeight="469.0" prefWidth="514.0">
          <children>
            <ListView prefWidth="200.0" prefHeight ="-1"/>
            <ListView prefWidth="200.0" prefHeight ="-1"/>
            <ListView prefWidth="200.0" prefHeight ="-1"/>
          </children>
        </HBox>
      </children>
    </AnchorPane>
    Edited by: jsmith on Jul 17, 2012 5:22 PM

    On second thoughts, after reviewing your question, Ithink that my answer is overly simplistic and may not be of assistance - but I don't know how to delete it, so I'll leave it here for now.

    Edited by: jsmith on Jul 17, 2012 6:02 PM

    Maybe you should use VBoxes instead of ListViews - they don't have scroll controls so they willl size pref height exactly to their content automatically.
  • 2. Re: FXML SplitPane > TitledPane > ScrollPane > AnchorPane > ListView
    daniel Journeyer
    Currently Being Moderated
    Hi,

    You could try anchoring your list views inside the AnchorPane. That's what the AnchorPane is for after all ;-)
    If you're using SceneBuilders the anchors will appear in the Layout section of the Inspector panel on the right, when you select any node contained in an AnchorPane.

    Hope this helps,

    -- daniel
  • 3. Re: FXML SplitPane > TitledPane > ScrollPane > AnchorPane > ListView
    949137 Newbie
    Currently Being Moderated
    I don't think vbox would work since I use selected item and my items are a list of my own class.

    I have been playing with anchoring and still have not come up with something that looks right.

    Looks like setting the size of the control from code is the only option here to get things to work the way we want.

Legend

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