开发者

Argument of setHorizontalGroup()

The method setHorizontalGroup is defined as: setHorizontalGroup(GroupLayout.Group group) .I dont understand it's argument after going through this :

lay开发者_如何学Goout.setHorizontalGroup(
layout.createSequentialGroup()
  .addComponent(c1)
  .addComponent(c2)
  .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
       .addComponent(c3)
       .addComponent(c4))
);

How are we adding all this?


This is an example of method chaining. If you look at the methods of GroupLayout.Group, you will notice that all the methods return a reference to the object on which it was called, so that you can chain multiple calls together.

The code you posted is equivalent to the following:

GroupLayout.Group group = layout.createSequentialGroup();
group.addComponent(c1);
group.addComponent(c1);
group.addGroup(...);
layout.setHorizontalGroup(group);

Since group.addComponent(c1) returns group, you can chain the calls and write group.addComponent(c1).addComponent(c2).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜