当前位置:网站首页 > Java教程 > 正文

java盒子使用教程



布局管理器,允许垂直或水平布置多个组件。 这些部件不会包裹,因此,例如,当调整框架尺寸时,垂直布置的部件将保持垂直布置。 Example:

The following text describes this graphic.

使用水平和垂直的不同组合嵌套多个面板会产生类似于GridBagLayout的效果,而不会产生复杂性。 该图显示了两个水平排列的面板,每个面板包含垂直排列的3个组件。

BoxLayout管理器使用轴参数构造,该参数指定将要完成的布局类型。 有四种选择:

- Components are laid out horizontally from left to right.
- Components are laid out vertically from top to bottom.
- Components are laid out the way words are laid out in a line, based on the container's property. If the container's is horizontal then components are laid out horizontally, otherwise they are laid out vertically. For horizontal orientations, if the container's is left to right then components are laid out left to right, otherwise they are laid out right to left. For vertical orientations components are always laid out from top to bottom.
- Components are laid out the way text lines are laid out on a page, based on the container's property. If the container's is horizontal then components are laid out vertically, otherwise they are laid out horizontally. For horizontal orientations, if the container's is left to right then components are laid out left to right, otherwise they are laid out right to left. For vertical orientations components are always laid out from top to bottom.

对于所有方向,组件的排列顺序与添加到容器中的顺序相同。

BoxLayout尝试以其首选宽度(水平布局)或高度(垂直布局)排列组件。 对于水平布局,如果不是所有组件都具有相同的高度,BoxLayout会尝试使所有组件与最高组件一样高。 如果对于特定组件不可能,则BoxLayout根据组件的Y对齐垂直对齐该组件。 默认情况下,组件的Y对齐为0.5,这意味着组件的垂直中心应与具有0.5 Y对齐的其他组件的垂直中心具有相同的Y坐标。

类似地,对于垂直布局,BoxLayout尝试使列中的所有组件与最宽的组件一样宽。 如果失败,则根据X对齐水平对齐它们。 对于布局,水平对齐基于组件的前沿完成。 换句话说,如果容器的从左到右,则X对齐值0.0表示组件的左边缘,否则表示组件的右边缘。

许多程序使用Box类,而不是直接使用BoxLayout。 Box类是一个使用BoxLayout的轻量级容器。 它还提供了方便的方法来帮助您很好地使用BoxLayout。 将组件添加到多个嵌套框是获得所需排列的有效方法。

有关更多信息和示例,请参阅“Java教程” How to Use BoxLayout部分

警告:此类的序列化对象与以后的Swing版本不兼容。 当前的序列化支持适用于运行相同版本Swing的应用程序之间的短期存储或RMI。 从1.4开始, 软件包中添加了对所有JavaBeans 长期存储的支持。 请参阅 。

  • 上一篇: java教程48讲
  • 下一篇: java手机版教程
  • 版权声明


    相关文章:

  • java教程48讲2025-03-12 13:50:06
  • java降级spring教程2025-03-12 13:50:06
  • java语言封装教程2025-03-12 13:50:06
  • 菜鸟java教程 array2025-03-12 13:50:06
  • java 变量教程2025-03-12 13:50:06
  • java手机版教程2025-03-12 13:50:06
  • mock教程 java2025-03-12 13:50:06
  • 后端java技术教程2025-03-12 13:50:06
  • java语言程序设计教程 周绍斌2025-03-12 13:50:06
  • java免费全教程2025-03-12 13:50:06