Layout question

I want to separate a panel to 3 smaller panels, with the different width 1/5, 2/5, 2/5. Could anyone help me out? Thanks a lot.1/52/5 2/5--- ---- ---- ---- ---- ---
[234 byte] By [YuDanga] at [2007-10-3 1:09:38]
# 1

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

m0rbida at 2007-7-14 18:06:32 > top of Java-index,Desktop,Core GUI APIs...
# 2

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.

YuDanga at 2007-7-14 18:06:32 > top of Java-index,Desktop,Core GUI APIs...
# 3
TableLayout will do this for you very easily.https://tablelayout.dev.java.net/
itchyscratchya at 2007-7-14 18:06:32 > top of Java-index,Desktop,Core GUI APIs...