I want to use two layout depending on circumstances. But when I build them in the constructor and save, when I use them they don`t work. When I build them every time before using it is work.

03-23-2011, 08:18 PM

doWhile

You'll probably receive faster and more constructive feedback if you provide more of a description - especially something in the form of an SSCCE with a clear definition of what you mean by 'doesn't work'.

03-24-2011, 05:21 AM

Itun

It works:
{
GroupLayout groupLayout = new GroupLayout(jPanel);
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(GroupLayout.Alignm ent.LEADING).
addComponent(jLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(GroupLayout.Alignm ent.LEADING).
addComponent(jLabel, GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE));
jPanel.setLayout(groupLayout);
}
It does not work:
GroupLayout groupLayout;
{
groupLayout = new GroupLayout(jPanel);
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(GroupLayout.Alignm ent.LEADING).
addComponent(jLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(GroupLayout.Alignm ent.LEADING).
addComponent(jLabel, GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE));
}
.
.
.
{
jPanel.setLayout(groupLayout);
}
I want to create a panel with Open/Close Button. May be there are another good variant how to create this panel without changing layout. For example, when I change size it is not appropriate, because size is changed from right to left and it covers my button.

03-24-2011, 06:19 PM

Itun

I suppose It is not also understandable.
I wrote a class.
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;