Why does ...
Group horizontalGroup = groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup()
.addComponent(aTextArea)
.addComponent(aButton,GroupLayout.Alignment.CENTER));
Group verticalGroup = groupLayout.createSequentialGroup()
.addComponent(aTextArea)
.addComponent(aButton);
... give this (as expected)
+--------------------------------------------------------------+
|+-------------------------------------------------------+ |
|| aTextArea | |
|| | |
|+-------------------------------------------------------+ |
| [aButton] |
| |
+--------------------------------------------------------------+
but ...
Group horizontalGroup = groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup()
.addComponent(aTextArea)
.addGroup(groupLayout.createParallelGroup
(GroupLayout.Alignment.CENTER)
.addComponent(aButton)));
Group verticalGroup = groupLayout.createSequentialGroup()
.addComponent(aTextArea)
.addComponent(aButton);
gives this?
+--------------------------------------------------------------+
|+-------------------------------------------------------+ |
|| aTextArea | |
|| | |
|+-------------------------------------------------------+ |
|[aButton] |
| |
+--------------------------------------------------------------+
Why does wrapping the aButton in a Parallel Group cause it to ignore the alignment? Adding the alignment also to the aButton itself has no effect.
I want to do something like this in order to have a mixture of groups of leading, trailing and central alignments beneath the aTextArea. It seems to me GroupLayout is rather limited IF it cannot cope with this.
This ...
.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.CENTER)
...
specifies that components WITHIN THE GROUP are aligned centrally WITH EACH OTHER.
To align the Group (all elements within the Group) against the parent Group specify the alignment as a parameter of the addGroup() method not of createParallelGroup():
.addGroup(GroupLayout.Alignment.CENTER, groupLayout.createParallelGroup()
...
I've not found this documented but it seems the addGroup(GroupLayout.Group group) form (no alignment specification) applies a LEADING alignment.
In this way SequentialGroups can also be aligned against a parent group.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.