Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Layout (desperate) Help

Thread view: 
pek - 05 Jul 2007 13:12 GMT
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.
Eric Sosman - 05 Jul 2007 16:58 GMT
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.
[quoted text clipped - 14 lines]
> 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.

Signature

Eric.Sosman@sun.com

pek - 15 Jul 2007 03:06 GMT
> pek wrote On 07/05/07 08:12,:
>
[quoted text clipped - 40 lines]
> --
> Eric.Sos...@sun.com

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.
Roedy Green - 05 Jul 2007 19:04 GMT
>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.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
RedGrittyBrick - 09 Jul 2007 00:22 GMT
> Please please please help me. I've tried every single Layout Manager
> and a lot of combinations but cannot still make is work.
[quoted text clipped - 15 lines]
> 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 :-)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.