【发布时间】:2017-01-17 18:12:52
【问题描述】:
我目前正在尝试将应用程序迁移到 JavaFX(它实际上部分使用 AWT),虽然将具有边框布局的 JPanel 切换到 BorderPanes 相当容易,但我在弄清楚如何使用GridBagLayout 和 GridPanes。 (我之前从未在 Swing 中使用过这种布局)
在我的代码中,GridBagLayout 被使用了 2 次(我不确定这是否是自动生成的代码):
JPanel bottomMessagePanel = new JPanel();
bottomMessagePanel.setLayout(new GridBagLayout());
bottomMessagePanel.setBorder(BorderFactory.createEmptyBorder());
bottomMessagePanel.add(someJComponent, new GridBagConstraints(0, 0, 1, 1, .35, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
bottomMessagePanel.add(someOtherJComponent, new GridBagConstraints(1, 0, 1, 1, .65, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
和
JPanel stepPanel = new JPanel();
stepPanel.setLayout(new GridBagLayout());
stepPanel.add(someJComponent, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
stepPanel.add(someOtherJComponent, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
stepPanel.add(some3rdJComponent, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
我将如何使用 JavaFX GridPane 做到这一点?
不要担心转换那些 JComponents,因为我已经转换了那些......
非常感谢任何帮助!
【问题讨论】:
标签: java swing user-interface javafx