Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX layout equivalent to GridLayout

I'm used to working with Swing to create GUIs but for a recent project I've chosen to switch to JavaFX. I'm having some trouble with recreating a certain layout I used to make using a GridLayout.

I desire the following behavior: 2 columns that scale proportionally with the size of their parent that center their contents.

Using Swing, I would make JPanel with a GridLayout (1 row, 2 columns) and add 2 JPanels with a BorderLayout, adding the actual content to those panels with the centered constraint. Then I could add the first panel to any container that has a layout that stretches with the frame and all would be well.

I seem to be unable to recreate this behavior in JavaFX in a simple way. I can think of ways to do it using bindings and combining several panes but I was hoping there is a layout that does this automatically. I've tried using TilePane, HBox, GridPane, AnchorPane, SplitPane and even BorderPane but none of them seem to do what I want them to.

Is there a recommended way to accomplish this? I would much prefer not to embed Swing into the application. Basically what I want is to be able to split the content into two columns that automatically stretch with the Stage/Scene (JFrame).

like image 711
RDM Avatar asked Oct 21 '22 01:10

RDM


1 Answers

GridPane? Some references here

  • http://docs.oracle.com/javafx/2/layout/builtin_layouts.htm#CHDGHCDG
  • http://docs.oracle.com/javafx/2/api/javafx/scene/layout/GridPane.html
like image 97
Flavio Avatar answered Oct 24 '22 11:10

Flavio