Which LayoutManager for this topic

Hi there!

I'm trying to arrange 3 JPanels in a JFrame like this:

++-+

| panel1| panel2|

++-+

||

| panel3|

||

||

+--+

On a resize, I want to maintain the relative size of the single panels, e.g.:

panel1.height = 1/4 of frame.height

panel3.height = 3/4 of frame.height

and the same for the widths of panel1 and panel2.

What layoutmanager would you recommend?

[448 byte] By [schorschi6a] at [2007-11-27 10:34:50]
# 1

package gui1;

/*

* LayoutDemo.java

*/

import java.awt.*;

import javax.swing.*;

public class LayoutDemo extends JFrame {

private JPanel jPanel1, jPanel2, jPanel3, jPanel4;

public LayoutDemo() {

super("Layout Demo");

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

setSize(400,300);

setLocationRelativeTo(null);

GridBagConstraints gridBagConstraints;

jPanel1 = new JPanel();

jPanel2 = new JPanel();

jPanel3 = new JPanel();

jPanel4 = new JPanel();

jPanel1.setLayout(new GridBagLayout());

jPanel2.setBackground(new Color(255, 255, 204));

gridBagConstraints = new GridBagConstraints();

gridBagConstraints.gridwidth = 2;

gridBagConstraints.fill = GridBagConstraints.BOTH;

gridBagConstraints.weightx = 2.0;

gridBagConstraints.weighty = 1.0;

jPanel1.add(jPanel2, gridBagConstraints);

jPanel3.setBackground(new Color(204, 204, 255));

gridBagConstraints = new GridBagConstraints();

gridBagConstraints.fill = GridBagConstraints.BOTH;

gridBagConstraints.weightx = 1.0;

gridBagConstraints.weighty = 1.0;

jPanel1.add(jPanel3, gridBagConstraints);

jPanel4.setBackground(new Color(255, 204, 204));

gridBagConstraints = new GridBagConstraints();

gridBagConstraints.gridx = 0;

gridBagConstraints.gridy = 1;

gridBagConstraints.gridwidth = 3;

gridBagConstraints.gridheight = 3;

gridBagConstraints.fill = GridBagConstraints.BOTH;

gridBagConstraints.weightx = 3.0;

gridBagConstraints.weighty = 3.0;

jPanel1.add(jPanel4, gridBagConstraints);

getContentPane().add(jPanel1, BorderLayout.CENTER);

}

public static void main(final String args[]) {new LayoutDemo().setVisible(true);}

}

Message was edited by:

Andre_Uhres

Andre_Uhresa at 2007-7-28 18:31:27 > top of Java-index,Desktop,Core GUI APIs...
# 2

Wow, thanks a lot, man!

Great, that was more than I expected to get...

schorschi6a at 2007-7-28 18:31:27 > top of Java-index,Desktop,Core GUI APIs...