JavaFX布局等同于GridLayout [英] JavaFX layout equivalent to GridLayout
问题描述
我习惯使用Swing创建GUI,但对于最近的项目,我选择切换到JavaFX。我在使用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.
我希望以下行为:
2列可按比例缩放他们的内容的中心大小。
I desire the following behavior: 2 columns that scale proportionally with the size of their parent that center their contents.
使用Swing,我会使用GridLayout(1行,2列)制作JPanel,并添加2个带有BorderLayout的JPanel,使用居中约束将实际内容添加到这些面板。
然后我可以将第一个面板添加到任何容器中,该容器的布局与框架一起伸展,一切都很好。
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.
我似乎无法以简单的方式在JavaFX中重新创建此行为。我可以想办法使用绑定和组合几个窗格来做到这一点,但我希望有一个布局自动执行此操作。我已经尝试过使用TilePane,HBox,GridPane,AnchorPane,SplitPane甚至BorderPane,但它们似乎都没有做我想要的。
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.
是否有推荐方式完成这个?我更不希望将Swing嵌入到应用程序中。基本上我想要的是能够将内容分成两列,用Stage / Scene(JFrame)自动拉伸。
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).
推荐答案
GridPane?这里有一些参考资料
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
- http://docs.oracle.com/javafx/2/layout/builtin_layouts.htm#CHDGHCDG
- http://docs.oracle.com/javafx/2/api/javafx/scene/layout/GridPane.html
这篇关于JavaFX布局等同于GridLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!