JavaFX layout equivalent to GridLayout

ⅰ亾dé卋堺 提交于 2020-01-13 12:06:48

问题


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).


回答1:


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


来源:https://stackoverflow.com/questions/18697347/javafx-layout-equivalent-to-gridlayout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!