Resizing Panels

Hi,I have 3 panels placed next to each other horizontally and i would like the change their sizes.Default their widht are the same.The 2nd panel should be 2x as big as the first one, and the 3rd panel should be the narrowest.Any help appreciated:Gabor
[279 byte] By [javahelpsa] at [2007-10-3 9:42:05]
# 1
Use gridbag lay out with help of thi you can set width to panel.
Prashant_SDNa at 2007-7-15 4:58:14 > top of Java-index,Desktop,Core GUI APIs...
# 2

Here is my code.I don't really know how to use Gridbag Layout. Why doesn't it work with setSize or setPreferredSize?

thx for any help.

import java.awt.Dimension;

import java.awt.GridLayout;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class threePanels{

JFrame frame;

JPanel panelLeft,panelCenter,panelRight,mainPanel;

JButton button1,button2,button3;

public threePanels(){

frame=new JFrame("3 panels in a frame");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

button1=new JButton("Left");

button2=new JButton("Center");

button3=new JButton("Right");

mainPanel=new JPanel(new GridLayout(1,0));

panelLeft=new JPanel();

panelLeft.setBorder(BorderFactory.createTitledBorder("1st panel"));

panelCenter=new JPanel();

panelCenter.setBorder(BorderFactory.createTitledBorder("2nd panel"));

panelRight=new JPanel();

panelRight.setBorder(BorderFactory.createTitledBorder("3rd panel"));

panelLeft.add(button1);

panelCenter.add(button2);

panelRight.add(button3);

/*

int width = 300;

panelLeft.setSize(width, 400);

panelCenter.setSize(width*2, 400);

panelRight.setSize(width/2, 400);

*/

int width = 100;

panelLeft.setPreferredSize(new Dimension(width,400));

panelCenter.setPreferredSize(new Dimension(width*2,400));

panelRight.setPreferredSize(new Dimension(width/2,400));

mainPanel.add(panelLeft);

mainPanel.add(panelCenter);

mainPanel.add(panelRight);

frame.add(mainPanel);

frame.pack();

frame.setVisible(true);

}

public static void main(String[] args){

javax.swing.SwingUtilities.invokeLater(new Runnable(){

public void run() {

threePanels start =new threePanels();

}

});

}

}

javahelpsa at 2007-7-15 4:58:14 > top of Java-index,Desktop,Core GUI APIs...
# 3
Use the "Code Formatting" tags when posting code.[url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers[/url].
camickra at 2007-7-15 4:58:14 > top of Java-index,Desktop,Core GUI APIs...