Java 布局管理器提示
Java Layout Manager tips
我创建了一个小程序,如 link 所示。我用过
绝对布局。但我想尝试其他布局。除了绝对布局之外,还有其他布局可供使用吗?
Here is the link
使用gridbaglayout。要正确使用它,请先阅读 gridbagconstraints。
作为不同意见,我不推荐GridBagLayout。它是最灵活的,所以你几乎可以用它做任何事情,但它很难使用。一种更简单的方法是使用组合方法,这意味着您的主 UI 中有多个面板,其中每个面板都有自己的布局。例如,对于顶部的两个组件,您可以使用垂直的 BoxLayout,对于底部的部分,您可以使用 FormLayout
但重点是,IMO 混合和匹配布局比对所有内容都使用一个超级灵活的布局更好。查看 this link 了解更多信息。他们提到了我推荐的内容:
Layout Managers are often mixed together in a single frame or dialog,
where a top level container has its own Layout Manager (often a
BoxLayout or BorderLayout), and smaller parts use their own layout,
completely independent of the others.
另一个不错的技巧是使用 GUI 构建器,例如 Eclipse 的 WindowBuilder 或 Netbean 的 Matisse;这样你就不用在代码中设计 UIs,它非常抽象
我创建了一个小程序,如 link 所示。我用过 绝对布局。但我想尝试其他布局。除了绝对布局之外,还有其他布局可供使用吗? Here is the link
使用gridbaglayout。要正确使用它,请先阅读 gridbagconstraints。
作为不同意见,我不推荐GridBagLayout。它是最灵活的,所以你几乎可以用它做任何事情,但它很难使用。一种更简单的方法是使用组合方法,这意味着您的主 UI 中有多个面板,其中每个面板都有自己的布局。例如,对于顶部的两个组件,您可以使用垂直的 BoxLayout,对于底部的部分,您可以使用 FormLayout
但重点是,IMO 混合和匹配布局比对所有内容都使用一个超级灵活的布局更好。查看 this link 了解更多信息。他们提到了我推荐的内容:
Layout Managers are often mixed together in a single frame or dialog, where a top level container has its own Layout Manager (often a BoxLayout or BorderLayout), and smaller parts use their own layout, completely independent of the others.
另一个不错的技巧是使用 GUI 构建器,例如 Eclipse 的 WindowBuilder 或 Netbean 的 Matisse;这样你就不用在代码中设计 UIs,它非常抽象