I have to make this Panel using GroupLayout, I have written the following code for it
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout
.createSequentialGroup()
.addComponent(label)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(installButton).addComponent(installProgressBar)
.addComponent(upadteLabel).addComponent(upadteButton)
.addComponent(removeButton)));
layout.setVerticalGroup(layout
.createParallelGroup()
.addComponent(label)
.addGroup(layout
.createSequentialGroup()
.addComponent(installButton)
.addGroup(layout.createParallelGroup()
.addComponent(installProgressBar)
.addComponent(upadteLabel))
.addComponent(upadteButton).addComponent(removeButton)));
layout.linkSize(SwingConstants.HORIZONTAL, installButton,
installProgressBar, upadteLabel, upadteButton, removeButton);
The installProgressBar and updateLabel have to share the same space(done).
But this is not making the buttons right alinged, i have tries using GroupLayout.Alignment.TRAILING in various places but was unable to get it working. \Basically i want the label to be of fix size(i can do that) and the label is to be left aligned while the buttons have to be right aligned.
Can somebody help me out and also explain how the alignment works.
To answer my own question adding a
preferredGap()
does the trick. The final code is