0

How can I in SceneBuilder to do left liquid left column, fixed center (here I will put GridPane - main part) and liquid right column on ScrollPane. The idea is very simple - if the width of the window is > width of the main part then the main part must be at the center of the window. If width of the window is < width of the main part then horizontal bar is shown. I would like to get solution for scenebuilder as I need a lot of such forms what is much easier to do via SB than via code

2 Answers2

1

You would use a StackPane because it will always center its children. Inside the pane you would create a ScrollPane with prefWidth set to the same value as prefWidth on your content. Also set maxWidth to USE_PREF_SIZE.

ScrollPane constraints

Then you create your content pane and drop it inside the ScrollPane.

Content pane constraints

Example output fxml:

<?xml version="1.0" encoding="UTF-8"?>

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


<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
           minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" 
           xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <ScrollPane fitToHeight="true" maxWidth="-Infinity" minWidth="50.0" 
                  prefHeight="200.0" prefWidth="550.0">
         <content>
            <GridPane gridLinesVisible="true" maxHeight="1.7976931348623157E308" 
                      maxWidth="-Infinity" minHeight="-Infinity" 
                      minWidth="-Infinity" prefHeight="500.0" 
                      prefWidth="550.0">
              <columnConstraints>
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
              </columnConstraints>
              <rowConstraints>
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
              </rowConstraints>
            </GridPane>
         </content>
      </ScrollPane>
   </children>
</StackPane>
J Atkin
  • 3,080
  • 2
  • 19
  • 33
  • This is almost I need. The only thing - why does it shows horizontal scrollbar always? I must show horizontal scrollbar only when window width < scrollbar width. –  Jun 09 '15 at 04:14
  • `ScrollPane` has a little bit of padding for the border and such. You could fix this problem by adding 3 to the `ScrollPane`'s width or shrinking the content pane by 3. Or better than that you could remove the padding from the `ScrollPane`. [See that here](http://stackoverflow.com/questions/17540137/javafx-scrollpane-border-and-background) – J Atkin Jun 09 '15 at 13:28
  • Could you take a look at this question http://stackoverflow.com/questions/30729958/javafx-combobox-max-width –  Jun 09 '15 at 13:37
0

It is a lot easier to create custom implementation of a container such as VBox, where you manipulate visible and managed properties of your 'horizontal bar' based on the width of your container.

Than you can make use of this container in Scene Builder

Eugene Ryzhikov
  • 17,131
  • 3
  • 38
  • 60
  • Can you describe how to do it to get what I need? –  Jun 05 '15 at 10:17
  • In short you can create a pane based on `BorderPane`, for example. Main part is set to center and bar is set to top. On change of the pane's width property, check the pref width of the main part and depending on which one is bigger change `visible` and `managed` properties of the bar. Hope this helps – Eugene Ryzhikov Jun 05 '15 at 14:39