java swing 分组_Java 的swing.GroupLayout布局管理器的使用方法和实例(转)

The following builds a panel consisting of two labels in one column, followed by two textfields in the next column:

JComponent panel = ...;

GroupLayout layout = new GroupLayout(panel);

panel.setLayout(layout);

// Turn on automatically adding gaps between components

layout.setAutoCreateGaps(true);

// Turn on automatically creating gaps between components that touch

// the edge of the container and the container.

layout.setAutoCreateContainerGaps(true);

// Create a sequential group for the horizontal axis.

GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();

// The sequential group in turn contains two parallel groups.

// One parallel group contains the labels, the other the text fields.

// Putting the labels in a parallel group along the horizontal axis // positions them at the same x location.

//

// Variable indentation is used to reinforce the level of grouping.

hGroup.addGroup(layout.createParallelGroup().

addComponent(label1).addComponent(label2));

hGroup.addGroup(layout.createParallelGroup().

addComponent(tf1).addComponent(tf2));

layout.setHorizontalGroup(hGroup);

// Create a sequential group for the vertical axis.

GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();

// The sequential group contains two parallel groups that align

// the contents along the baseline. The first parallel group contains

// the first label and text

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值