Layout (desperate) Help

P

pek

Please please please help me. I've tried every single Layout Manager
and a lot of combinations but cannot still make is work.

I created a prototype and uploaded a screenshot.
Here is how the panels should be placed in normal size:
http://pek.ekei.com/misc/help/exampleLayout_normal.png

Red boxes and buttons NEVER change size.
Yellow boxes expand left and right
and orange boxes expands everywhere.

Here is an example of the same window if resized to a bigger size:
http://pek.ekei.com/misc/help/exampleLayout_expanded.png

Please please help. I have no idea how to break this into smaller
panels and what LayoutManagers to use.
If possible, send me the code at my mail: p3k_me _at_ hotmail _dot_
com
Thank you very much.
 
E

Eric Sosman

pek wrote On 07/05/07 08:12,:
Please please please help me. I've tried every single Layout Manager
and a lot of combinations but cannot still make is work.

I created a prototype and uploaded a screenshot.
Here is how the panels should be placed in normal size:
http://pek.ekei.com/misc/help/exampleLayout_normal.png

Red boxes and buttons NEVER change size.
Yellow boxes expand left and right
and orange boxes expands everywhere.

Here is an example of the same window if resized to a bigger size:
http://pek.ekei.com/misc/help/exampleLayout_expanded.png

Please please help. I have no idea how to break this into smaller
panels and what LayoutManagers to use.
If possible, send me the code at my mail: p3k_me _at_ hotmail _dot_
com

If I understand what you're trying for, I think
this arrangement will do it:

- panel 1 uses BorderLayout
- NORTH place holds panel 2, using BoxLayout (Y_AXIS)
- panel 3 uses FlowLayout, and holds eight red boxes
- panel 4 uses GridLayout, and holds two yellow boxes
- panel 5 uses BorderLayout
- WEST place holds one red box
- CENTER place holds one yellow box
- CENTER place holds orange box
- SOUTH place holds panel 6, using BorderLayout
- WEST place holds one red box
- CENTER place holds one yellow box
- EAST place holds panel 7, using BoxLayout (X_AXIS)
- one red box
- panel 8, using BoxLayout (Y_AXIS)
- two gray buttons

.... but it's possible I've misunderstood you.
 
R

Roedy Green

Red boxes and buttons NEVER change size.
Yellow boxes expand left and right
and orange boxes expands everywhere.

This is usually the desired behaviour. You can use the ipadx feature
of Grid bag layouts to plumpen up your buttons.

You can use the growth growth percentage feature to allocate
additional space to various components with grid bags.

See http://mindprod.com/jgloss/gridbaglayouts for rules of thumb.

Your screenshot shows you have mastered most of this already.
 
R

RedGrittyBrick

pek said:
Please please please help me. I've tried every single Layout Manager
and a lot of combinations but cannot still make is work.

I created a prototype and uploaded a screenshot.
Here is how the panels should be placed in normal size:
http://pek.ekei.com/misc/help/exampleLayout_normal.png

Red boxes and buttons NEVER change size.
Yellow boxes expand left and right
and orange boxes expands everywhere.

Here is an example of the same window if resized to a bigger size:
http://pek.ekei.com/misc/help/exampleLayout_expanded.png

Please please help. I have no idea how to break this into smaller
panels and what LayoutManagers to use.
If possible, send me the code at my mail: p3k_me _at_ hotmail _dot_
com
Thank you very much.

Here's one way to do it using only nested BoxLayouts

package Misc;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class LayoutProblem extends JPanel {

LayoutProblem() {
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
add(Box.createRigidArea(new Dimension(0,5)));

JPanel row1Panel = new JPanel();
row1Panel.setLayout(
new BoxLayout(row1Panel, BoxLayout.LINE_AXIS));
for (int i = 0; i < 8; i++) {
row1Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row1Panel.add(makeRedBox());
}
row1Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row1Panel.add(Box.createHorizontalGlue()); // else boxes centred
add(row1Panel);
add(Box.createRigidArea(new Dimension(0,5)));

JPanel row2Panel = new JPanel();
row2Panel.setLayout(
new BoxLayout(row2Panel, BoxLayout.LINE_AXIS));
row2Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row2Panel.add(makeYellowBox(100));
row2Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row2Panel.add(makeYellowBox(100));
row2Panel.add(Box.createRigidArea(new Dimension(5, 0)));
add(row2Panel);
add(Box.createRigidArea(new Dimension(0,5)));

JPanel row3Panel = new JPanel();
row3Panel.setLayout(
new BoxLayout(row3Panel, BoxLayout.LINE_AXIS));
row3Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row3Panel.add(makeRedBox());
row3Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row3Panel.add(makeYellowBox(30));
row3Panel.add(Box.createRigidArea(new Dimension(5, 0)));
add(row3Panel);
add(Box.createRigidArea(new Dimension(0,5)));

JPanel row4Panel = new JPanel();
row4Panel.setLayout(
new BoxLayout(row4Panel, BoxLayout.LINE_AXIS));
row4Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row4Panel.add(makeOrangeBox());
row4Panel.add(Box.createRigidArea(new Dimension(5, 0)));
add(row4Panel);
add(Box.createRigidArea(new Dimension(0,5)));

JPanel row5Panel = new JPanel();
row5Panel.setLayout(
new BoxLayout(row5Panel, BoxLayout.LINE_AXIS));
row5Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row5Panel.add(makeRedBox());
row5Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row5Panel.add(makeYellowBox(30));
row5Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row5Panel.add(makeRedBox());
row5Panel.add(Box.createRigidArea(new Dimension(5, 0)));
row5Panel.add(makeButtonPanel());
row5Panel.add(Box.createRigidArea(new Dimension(5, 0)));
add(row5Panel);
add(Box.createRigidArea(new Dimension(0,5)));
}

JPanel makeRedBox() {
JPanel p = new JPanel();
p.setBackground(Color.RED);
Dimension d = new Dimension(30,30);
p.setPreferredSize(d);
p.setMaximumSize(d);
return p;
}

JPanel makeYellowBox(int height) {
JPanel p = new JPanel();
p.setBackground(Color.YELLOW);
p.setPreferredSize(new Dimension(height, height));
p.setMaximumSize(new Dimension(9999,height));
return p;
}

JPanel makeOrangeBox() {
JPanel p = new JPanel();
p.setBackground(Color.ORANGE);
Dimension d = new Dimension(100,100);
p.setPreferredSize(d);
return p;
}

JPanel makeButtonPanel() {
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
p.add(new JButton("Button"));
p.add(new JButton("Button"));
return p;
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame("");
f.add(new LayoutProblem());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
});
}
}


Of course, the buttons need to be made smaller but at this point I got
bored :)
 
P

pek

pek wrote On 07/05/07 08:12,:








If I understand what you're trying for, I think
this arrangement will do it:

- panel 1 uses BorderLayout
- NORTH place holds panel 2, using BoxLayout (Y_AXIS)
- panel 3 uses FlowLayout, and holds eight red boxes
- panel 4 uses GridLayout, and holds two yellow boxes
- panel 5 uses BorderLayout
- WEST place holds one red box
- CENTER place holds one yellow box
- CENTER place holds orange box
- SOUTH place holds panel 6, using BorderLayout
- WEST place holds one red box
- CENTER place holds one yellow box
- EAST place holds panel 7, using BoxLayout (X_AXIS)
- one red box
- panel 8, using BoxLayout (Y_AXIS)
- two gray buttons

... but it's possible I've misunderstood you.

I tried your's and it worked right away. I was stunned! It is perfect!
In case anybody wonders, here is the source file and the code:

Source: http://pek.ekei.com/misc/help/Main.java
Code: http://pek.ekei.com/misc/help/solution.html

I'll keep you in mind for future layout requests. ;) Thank you very
very much.

P.S. I'll try the Box solution too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top