Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to create a flexible 3 box layout in JavaFX/FXML

Tags:

fxml

javafx-2

I want to create a flexible 3-box layout in JavaFX/FXML. A picture describes it the best, so just like in the following:

preferred outcome

As you can see, the main part should consist of three resizable boxes. All of this boxes should have a preferred size.

So the code looks like the following (simplified code).

<BorderPane>
  <top>
    <VBox>
      <!-- menubar stuff -->
    </VBox>
  </top>
  <center>
    <!-- ACTUAL CONTENT HERE -->
  </center>
  <bottom>
    <!-- toolbar stuff -->
  </bottom>
</BorderPane>

What could be the best approach here? Two nested SplitPanes?

like image 286
Appleshell Avatar asked Apr 18 '13 22:04

Appleshell


People also ask

Which pane layout should you use for laying out controls in 2 row and 3 column style?

GridPane. The GridPane layout pane enables you to create a flexible grid of rows and columns in which to lay out nodes. Nodes can be placed in any cell in the grid and can span cells as needed.

Can you add multiple panes to a scene in JavaFX?

The Scene it self can only have one root Pane. So if you want 2 panes in the Scene you need 3.

What is the difference between HBox and VBox pane?

HBox is a subclass of Pane that lays out its children next to each other, in a horizontal row. VBox is a subclass of Pane that lays out its children in vertical column. An HBox might be used as the bottom component in a BorderPane, making it possible to line up several components along the bottom of the border pane.


1 Answers

What could be the best approach here? Two nested SplitPanes?

Yep, I'd do that.

mapeditor

To get the mock layout above, try the opening the following fxml in SceneBuilder 1.1 early access.

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

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<BorderPane id="BorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="400.0" xmlns:fx="http://javafx.com/fxml">
  <bottom>
    <Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-background-color: linear-gradient(to bottom, paleturquoise, azure, paleturquoise);&#10;" text="(56, 32)" textAlignment="LEFT" BorderPane.alignment="CENTER" />
  </bottom>
  <center>
    <SplitPane dividerPositions="0.3492462311557789" focusTraversable="true" prefHeight="160.0" prefWidth="200.0">
      <items>
        <SplitPane id="SplitPane" dividerPositions="0.6088328075709779" orientation="VERTICAL">
          <items>
            <TabPane prefHeight="200.0" prefWidth="200.0" side="BOTTOM" tabClosingPolicy="UNAVAILABLE">
              <tabs>
                <Tab text="A">
                  <content>
                    <TilePane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: lavender;&#10;" />
                  </content>
                </Tab>
                <Tab text="B">
                  <content>
                    <TilePane prefHeight="200.0" prefWidth="200.0" />
                  </content>
                </Tab>
                <Tab text="C">
                  <content>
                    <TilePane prefHeight="200.0" prefWidth="200.0" />
                  </content>
                </Tab>
                <Tab text="D">
                  <content>
                    <TilePane prefHeight="200.0" prefWidth="200.0" />
                  </content>
                </Tab>
                <Tab text="E">
                  <content>
                    <TilePane prefHeight="200.0" prefWidth="200.0" />
                  </content>
                </Tab>
              </tabs>
            </TabPane>
            <TreeView prefHeight="200.0" prefWidth="200.0" />
          </items>
        </SplitPane>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="80.0" prefWidth="50.0" style="-fx-background-color: palegreen;" />
      </items>
    </SplitPane>
  </center>
  <top>
    <VBox prefHeight="-1.0" prefWidth="-1.0">
      <children>
        <MenuBar>
          <menus>
            <Menu mnemonicParsing="false" text="File">
              <items>
                <MenuItem mnemonicParsing="false" text="Close" />
              </items>
            </Menu>
            <Menu mnemonicParsing="false" text="Edit">
              <items>
                <MenuItem mnemonicParsing="false" text="Delete" />
              </items>
            </Menu>
            <Menu mnemonicParsing="false" text="Help">
              <items>
                <MenuItem mnemonicParsing="false" text="About" />
              </items>
            </Menu>
          </menus>
        </MenuBar>
        <ToolBar>
          <items>
            <Button mnemonicParsing="false" style="-fx-graphic: url('http://icons.iconarchive.com/icons/custom-icon-design/pretty-office-9/24/open-file-icon.png');" text="" />
            <Button mnemonicParsing="false" style="-fx-graphic: url('http://icons.iconarchive.com/icons/custom-icon-design/pretty-office-7/24/Save-icon.png');" text="" />
          </items>
        </ToolBar>
      </children>
    </VBox>
  </top>
</BorderPane>
like image 109
jewelsea Avatar answered Sep 28 '22 22:09

jewelsea