setPreferredSize() & setSize() of JPanel don't work as expected.
843807Feb 2 2010 — edited Feb 2 2010http://myhome.cari.com.my/attachment/201002/1/195233_1265032535pmPA.jpg
Above link show what i want to do,but it doesn't show as expected after i run the code below.
//-----------START-----------
import javax.swing.*;
import java.awt.*;
public class Testing extends JPanel
{
public Testing()
{ setLayout(new GridLayout(1,2));
JPanel leftPanel=new JPanel();
leftPanel.setPreferredSize(new Dimension(224,768));
leftPanel.setBorder(BorderFactory.createLineBorder(Color.black));
JPanel rightTopPanel=new JPanel();
rightTopPanel.setPreferredSize(new Dimension(800,576));
rightTopPanel.setBorder(BorderFactory.createLineBorder(Color.blue));
JPanel rightBottomPanel=new JPanel();
rightBottomPanel.setPreferredSize(new Dimension(800,192));
rightBottomPanel.setBorder(BorderFactory.createLineBorder(Color.red));
JPanel rightPanel=new JPanel(new GridLayout(2,1));
rightPanel.setPreferredSize(new Dimension(800,768));
rightPanel.setBorder(BorderFactory.createLineBorder(Color.yellow));
rightPanel.add(rightTopPanel);
rightPanel.add(rightBottomPanel);
add(leftPanel);
add(rightPanel);
}
public static void main(String[] args)
{ JFrame frame=new JFrame("Testing!!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setContentPane(new Testing());
frame.getContentPane().setPreferredSize(new Dimension(1440,800));
frame.pack();
frame.setVisible(true);
}
}
//--------------END-------------------
Edited by: ImMax on Feb 2, 2010 3:56 PM
Edited by: ImMax on Feb 2, 2010 3:57 PM