You mean like this ?
import java.awt.*;
import javax.swing.*;
public class panels
{
private Container c;
JPanel mainPanel, firstPanel, secondPanel, thirdPanel;
panels () throws Exception
{
firstPanel = new JPanel ();
secondPanel = new JPanel ();
thirdPanel = new JPanel ();
firstPanel.setBorder (BorderFactory.createCompoundBorder (
BorderFactory.createTitledBorder (""),
BorderFactory.createEmptyBorder (10, 5, 10, 5)));
secondPanel.setBorder (BorderFactory.createCompoundBorder (
BorderFactory.createTitledBorder (""),
BorderFactory.createEmptyBorder (20, 5, 20, 5)));
thirdPanel.setBorder (BorderFactory.createCompoundBorder (
BorderFactory.createTitledBorder (""),
BorderFactory.createEmptyBorder (20, 5, 20, 5)));
mainPanel = new JPanel ();
mainPanel.setLayout (new BoxLayout (mainPanel, BoxLayout.PAGE_AXIS));
//mainPanel.setBorder (BorderFactory.createEmptyBorder (5, 5, 5, 5));
mainPanel.add (firstPanel);
mainPanel.add (secondPanel);
mainPanel.add (thirdPanel);
JFrame jf = new JFrame ("three panels");
jf.setLocation (100, 100);
jf.setSize (260, 250);
jf.setBackground (Color.white);
jf.setResizable (false);
c = jf.getContentPane ();
c.add (mainPanel);
jf.setVisible (true);
}
public static void main (String[] args) throws Exception
{
new panels ();
}
}
mfg
m0rbid
When I set jf.setResizable (true), these sub-panels don't show the size proportion. The format I want is
1/5 2/5 2/5
#############################
#-#--#--#
#-#--#--#
#-#--#--#
#-#--#--#
#-#--#--#
#-#--#--#
#############################
I was considering if I can use BoxLayout or GridBagLayout, maybe adding some constrains. Anyway, thanks for your help.