In my application, there are 4 panels. And i need to insert them into the main panel, which uses BorderLayout. The 4 panels are…
- A thin Image strip.
- 4 buttons just below above
- A TextField covering the complete page.
- An about at end.
This is my code…
add(imageLabel, BorderLayout.NORTH);
add(buttonPanel,BorderLayout.PAGE_START);
add(logScrollPane, BorderLayout.CENTER);
add(about, BorderLayout.PAGE_END);
When I do this, the buttonPanel disappears. How can I achieve what I need?
I usually try to keep a maximum of 3 components in any
BorderLayout, so I would do it like this…As long as you keep the ‘maximum-stretched’ component in the
CENTER(in this case, yourlogScrollPane) then it’ll always work. If you want to use the panel, such as setting it on aJFrame, just useadd(outerPanel).Don’t be afraid of
BorderLayout– the ability of this layout to auto-expand theCENTERcomponent to fill the available space make it a very powerful and very importantLayoutManager!