JPanel with many children doesn't display them all in a narrow window

I'm writing an application that has a JPanel at the top containing many

JToolBars. However, the height of the JPanel stays constant when I narrow

the application window so that many of the JToolBars are not displayed.

I would like to have the JPanel increase in height as the window narrows

so that all the JToolBars remain visible.How can you do this? Thanks.

Try widening/narrowing the window in this example:

-

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

publicclass Sampleextends JFrame{

public Sample(String name){

super(name);

JPanel tp =new JPanel(new FlowLayout());

for (int i = 0; i < 10; i++){

JToolBar tb =new JToolBar("toolbar" + i);

for (int j = 0; j < 10; j++){

tb.add(new AbstractAction(("Action" + i) + j){

publicvoid actionPerformed(ActionEvent event){

}

});

}

tp.add(tb);

}

JPanel cp =new JPanel();

cp.setSize(400, 400);

cp.setBackground(Color.red);

add(tp, BorderLayout.PAGE_START);

add(cp, BorderLayout.CENTER);

}

publicstaticvoid main(String[] args){

Sample s =new Sample("Sample");

s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

s.setSize(500, 500);

s.setVisible(true);

}

}

[2597 byte] By [Greg.Ariasa] at [2007-11-26 15:58:23]
# 1
There are some neat tricks in this thread. http://forum.java.sun.com/thread.jspa?threadID=716580&messageID=4190052
JSnakea at 2007-7-8 22:19:27 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks - the ModifiedFlowLayout seems to do the job.
Greg.Ariasa at 2007-7-8 22:19:27 > top of Java-index,Desktop,Core GUI APIs...