Resizing JPanel?

I am new to Java and learning the layouts...I am using a GridLayout and attempting to put JPanels thatc ontain other widgets inside the layout . My top panel is a graphic that has a height of 79....this is the ONLY panel that I want to have a height of 79....the others I would like to make 35, but the only way I have been able to make the header graphic fully display is by increasing the SetSize paramater of the whole window....but doing so stretches out the other panels and leaves too much white space. How can I individually size the JPanels? or can I?

import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

publicclass GUIextends JFrame

implements ActionListener

{

private JButton button1, button2, button3;

private JLabel label1, label2, label3,label4, label5, headLabel;;

private JTextField text1, text2, text3, text4, text5;

// Constructor - GUI Window

public GUI()

{

// Basic Window Propertes

setTitle("Merchant");

setSize(750, 370);

setLocation(400,200);

// Grid Setup

GridLayout mainGrid =new GridLayout(4,1);

setLayout(mainGrid);

ImageIcon header =new ImageIcon("image.jpg");

headLabel =new JLabel(header);

// Create Input Labels

label1 =new JLabel("Name:", JLabel.CENTER);

label2 =new JLabel("QNumber:", JLabel.CENTER);

label3 =new JLabel("Cost:", JLabel.CENTER);

// Create Input Text Fields

text1 =new JTextField(15);

text1.setEnabled(true);

text2 =new JTextField(3);

text2.setEnabled(true);

text3 =new JTextField(7);

text3.setEnabled(true);

// Create Action Buttons

button1 =new JButton("Sale");

button2 =new JButton("Return");

button3 =new JButton("Invoice");

// Create Output Labels

label4 =new JLabel("Amount of Transaction:", JLabel.CENTER);

label5 =new JLabel("Current Balance:", JLabel.CENTER);

// Create Input Text Fields

text4 =new JTextField(8);

text4.setEnabled(true);

text5 =new JTextField(8);

text5.setEnabled(true);

// *************************** JPanel Layout ***************************

// Add Header Panel to Layout

JPanel headPanel =new JPanel();

headPanel.setBackground(Color.white);

headPanel.add(headLabel);

//headPanel.setPreferredSize(new Dimension(750, 79));

add(headPanel,"Header");

// Add Top Panel to Layout

JPanel topPanel =new JPanel();

topPanel.setBackground(Color.white);

topPanel.add(label1);

topPanel.add(text1);

topPanel.add(label2);

topPanel.add(text2);

topPanel.add(label3);

topPanel.add(text3);

add(topPanel,"Top");

// Add Middle Panel to Layout

JPanel midPanel =new JPanel();

midPanel.setBackground(Color.white);

midPanel.add(button1);

midPanel.add(button2);

midPanel.add(button3);

add(midPanel,"Middle");

//Add Bottom Panel to Layout

JPanel botPanel =new JPanel();

botPanel.setBackground(Color.white);

botPanel.add(label4);

botPanel.add(text4);

botPanel.add(label5);

botPanel.add(text5);

add(botPanel,"Bottom");

// *********************************************************************

// Listeners

button1.addActionListener(this);

button2.addActionListener(this);

button3.addActionListener(this);

// Make Visible

setVisible(true);

}

// Method - Checks to see if the user has performed an action

publicvoid actionPerformed(ActionEvent e){

// Check to see which button initiated the event

if (e.getSource() == button1)

{

System.err.println("Button 1 is HOT");

}

elseif (e.getSource() == button2)

{

System.err.println("Button 2 is HOT");

}

elseif (e.getSource() == button3)

{

System.err.println("Button 3 is HOT");

InvoiceFrame frame =new InvoiceFrame();

}

}

}

[6985 byte] By [OpenIntroa] at [2007-10-3 9:25:47]
# 1
Don't put them all in the same gridlayout or they will all be the same size. You can mix layouts and you can layer layouts.
zadoka at 2007-7-15 4:39:56 > top of Java-index,Desktop,Core GUI APIs...
# 2
So don't use GridLayout at all or are you suggesting a different GridLayout for each Panel?
OpenIntroa at 2007-7-15 4:39:56 > top of Java-index,Desktop,Core GUI APIs...
# 3
I don't know what else is in your gui but based on what I know:Use one gridlayout for everything that needs to be the same size on the top.Use one gridlayout for everything else.Put them together inside of a box layout or a border layout.
zadoka at 2007-7-15 4:39:56 > top of Java-index,Desktop,Core GUI APIs...
# 4
I guess I'm unclear as to how I implement multiple GridLayouts.....my entire GUI is what I pasted in the above code....
OpenIntroa at 2007-7-15 4:39:56 > top of Java-index,Desktop,Core GUI APIs...
# 5

> I guess I'm unclear as to how I implement multiple GridLayouts.....

JPanel panel1 = new JPanel( new GridLayout(....) );

panel1.add(....);

JPanel panel2 = new JPanel( new GridLayout(....) );

panel2.add(...);

getContentPane().add(panel1, BorderLayout.NORTH);

getContentPane().add(panel2, BorderLayout.SOUTH);

Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers[/url] and then mix and match until you get the desired layout.

> my entire GUI is what I pasted in the above code....

Its not executable so we can't see what you are trying to describe:

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-15 4:39:56 > top of Java-index,Desktop,Core GUI APIs...