Say I have a frame and I want to create 6 panels in it like so:
which layout would be the best? I tried something like this:
public static void main ( String[] args ) {
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(800,600));
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
JPanel leftTop = new JPanel();
leftTop.setPreferredSize(new Dimension(251,300));
leftTop.setBackground(Color.black);
frame.getContentPane().add(leftTop);
JPanel middleTop = new JPanel();
middleTop.setPreferredSize(new Dimension(251,300));
middleTop.setBackground(Color.white);
frame.getContentPane().add(middleTop);
JPanel rightTop = new JPanel();
rightTop.setPreferredSize(new Dimension(251,300));
rightTop.setBackground(Color.red);
frame.getContentPane().add(rightTop);
JPanel leftBottom = new JPanel();
leftBottom.setPreferredSize(new Dimension(251,300));
leftBottom.setBackground(Color.green);
frame.getContentPane().add(leftBottom);
JPanel middleBottom = new JPanel();
middleBottom.setPreferredSize(new Dimension(251,300));
middleBottom.setBackground(Color.yellow);
frame.getContentPane().add(middleBottom);
JPanel rightBottom = new JPanel();
rightBottom.setPreferredSize(new Dimension(251,300));
rightBottom.setBackground(Color.black);
frame.getContentPane().add(rightBottom);
frame.pack();
frame.setVisible(true);
}
but if I change the size of a panel it will not turn out so nice haha.