-
Layouts and Sizes
Hi, I was wondering if somebody can help me out with a way to do this. I need to create a layout that has 4 places, all should be same sizes and the panels needs to be same length all the time.
here is a picture how i want it to look, also I am putting my code with picture of results i get with this code.
I want it to look like this:
http://imageshack.us/photo/my-images...siredlook.jpg/
This is my code
Code:
package container;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.geom.Rectangle2D;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class trailer extends JFrame
{
private JPanel pnl_topView = new JPanel();
private JPanel pnl_leftView = new JPanel();
private JPanel pnl_rightView = new JPanel();
private JPanel pnl_threePanels = new JPanel();
private JPanel pnl_bottom = new JPanel();
private void initialize()
{
pnl_leftView.setBorder(BorderFactory.createLineBorder(Color.black));
pnl_leftView.setSize(100, 100);
pnl_rightView.setBorder(BorderFactory.createLineBorder(Color.black));
pnl_rightView.setSize(200, 200);
pnl_topView.setBorder(BorderFactory.createLineBorder(Color.black));
pnl_topView.setSize(300, 300);
pnl_bottom.setBorder(BorderFactory.createLineBorder(Color.black));
pnl_threePanels.setLayout(new BorderLayout());
}
private void addToPanels()
{
pnl_threePanels.add(pnl_topView, BorderLayout.NORTH);
pnl_threePanels.add(pnl_rightView, BorderLayout.CENTER);
pnl_threePanels.add(pnl_leftView, BorderLayout.SOUTH);
}
public trailer()
{
this.setSize(500, 500);
this.setTitle("Trailer Panel Loader");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.add(pnl_threePanels, BorderLayout.NORTH);
this.add(pnl_bottom, BorderLayout.SOUTH);
initialize();
addToPanels();
}
public static void main(String[] args)
{
new trailer().setVisible(true);
}
}
With the code it looks like this
http://imageshack.us/photo/my-images...rrentlook.jpg/
I understand that border layout can not preset sizes, i Just don't know any other way that i can set a size to a panel and make it show full size without it being packed to minimum size?
-
Why not use a simple GridLayout with four rows and a single column?
kind regards,
Jos
-