Can you help me with some short code like how to resize a Toolbar when the maximize button is pressed..
I'll do better. Here's a short code sample that shows 5 of them with different resize behavior depending on where they are placed in a BorderLayout
.

import java.awt.BorderLayout;
import javax.swing.*;
public class ResizableToolBars {
public static void showFrameWithToolBar(String toolBarPosition) {
// the layout is important..
JPanel gui = new JPanel(new BorderLayout());
JToolBar tb = new JToolBar();
// ..the constraint is also important
gui.add(tb, toolBarPosition);
tb.add(new JButton("Button 1"));
tb.add(new JButton("Button 2"));
tb.addSeparator();
tb.add(new JButton("Button 3"));
tb.add(new JCheckBox("Check 1", true));
JFrame f = new JFrame(toolBarPosition + " Sreeeetchable Tool Bar");
f.setContentPane(gui);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setLocationByPlatform(true);
f.pack();
// we don't normally set a size, this is to show where
// extra space is assigned.
f.setSize(400,120);
f.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
showFrameWithToolBar(BorderLayout.PAGE_START);
showFrameWithToolBar(BorderLayout.PAGE_END);
showFrameWithToolBar(BorderLayout.LINE_START);
showFrameWithToolBar(BorderLayout.LINE_END);
showFrameWithToolBar(BorderLayout.CENTER);
}
});
}
}
If you come back to the Nested Layout Example after that, you should be able to figure out how I put it together from smaller groups of components, each in their own layout (in a panel) in one area of a parent container.
