tags:

views:

63

answers:

3

Hi all,

In my application, I have a layout similar to what is shown below:

@@@@@@@
XXXXXXX***
XXXXXXX***
XXXXXXX***
%%%%%%%

In this layout, X is a JTable. The other components can remain the same size. Is there a layout or strategy that will have the JTable (X) resize based on available screen size and have everything else stay on the sides properly?

Thanks.

+5  A: 

That looks very much like a BorderLayout to me. Have you tried that?

Paul Clapham
How can you keep the top and bottom components from taking up the entire width of the BorderLayout? When I try it, it will fill all three components horizontally.
Tony Eichelberger
You can use three BorderLayout panels p1, p2, p3 with '@' set to the NORTH of p1, 'X' the CENTER of p1, '%' the SOUTH of p1.'*' the CENTER of p2 with Box.createRigidArea(size) add to north and sourth.and p3 will contain both p1 and p2 with p1 as the CENTER and p2 as the EAST.
dennisjtaylor
Yes, I knew you could do it with multiple layouts. I was just curious if the initial answer was indicating it could be done with just one layout.
Tony Eichelberger
A: 

It can also be done with GroupLayout, but it is designed for GUI builders, as it's very verbose. So if you already have existing code, you might not want to try it first.

unholysampler
A: 

I am a big fan of JGoodies FormLayout. Here is some sample code of one way to do this with FormLayout.

    JPanel panel = new JPanel();        
    FormLayout layout = new FormLayout("100dlu, 20dlu:grow", "pref, pref, pref");
    panel.setLayout(layout);

    JTextField t1 = new JTextField();
    JTextField t2 = new JTextField();
    JTable tb = new JTable();
    JScrollPane sp = new JScrollPane();
    sp.setViewportView(tb);

    CellConstraints cc = new CellConstraints();
    panel.add(t1, cc.xy(1, 1));
    panel.add(t2, cc.xy(1, 3));
    panel.add(sp, cc.xyw(1, 2, 2));
Tony Eichelberger