Creating a type of BorderLayout with 2 PAGE_START areas
Is there a better way to recreate this type of layout without having to use this many containers? Also, in my actual program, some empty space is created under the two bordered panels, presumably from all of the extra space from the embedded BorderLayouts (CENTER, PAGE_END, etc.) In my main program the JFrame uses a BorderLayout, and in the CENTER portion I have a CardLayout. One of the cards uses BorderLayout again with a JTabbedPane within its CENTER area. It is within one of these tabs that I wish to use this double PAGE_START type of layout. The CENTER portion of the frame's BorderLayout actually adds a JScrollPane, with the CardLayout inside it. When I use the pack() command the program does bring the frame's bottom up to the bottom of the second bordered pane, but because of this the vertical scrollbar appears, in order for the empty space immediately below to be contained also. I'm sure if there's a better way of doing this I won't have the problem of this extra empty space, yet I couldn't recreate it in this sample code.
Is there a better way to implement 2 panels into some sort of double PAGE_START configuration without this confusing setup? I'd like the panels to retain their heights, and stretch width-wise, both of whom, like in the code below, are put up at the top of their parent container.
Here's the code:
import javax.swing.border.TitledBorder;
import javax.swing.*;
import java.awt.*;
publicclass Test
{
publicstaticvoid main(String[] args)
{
//Initiate everything
JFrame frame =new JFrame();
JPanel main =new JPanel(new BorderLayout());
JPanel pOne =new JPanel(new BorderLayout());
JPanel sub =new JPanel(new BorderLayout());
JPanel pTwo =new JPanel();
TitledBorder bOne = BorderFactory.createTitledBorder("Area One");
TitledBorder bTwo = BorderFactory.createTitledBorder("Area Two");
//Apply borders
pOne.setBorder(bOne);
pTwo.setBorder(bTwo);
//Add components
frame.add(new JScrollPane(main));
main.add(pOne, BorderLayout.PAGE_START);
main.add(sub, BorderLayout.CENTER);
sub.add(pTwo, BorderLayout.PAGE_START);
pOne.add(new JTextField("Component 1"));
pTwo.add(new JButton("Component 2"));
//Finalize and display window
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Thanks!

