Reputation: 8001
I have a JFrame
that uses the BorderLayout
. How do I get all the components that are in the left or the right or in any other location of this JFrame
?
Upvotes: 2
Views: 312
Reputation: 9618
As @brano suggested, you can access those components via the LayoutManager
of your JFrame
's contentPane
.
For exemple, assuming that you want to get the component that is located on BorderLayout.WEST
(and that your JFrame
is called frame
), you could do:
final BorderLayout layout = (BorderLayout) frame.getContentPane().getLayout();
final Component west = layout.getLayoutComponent(BorderLayout.WEST);
One remark, though: the getLayoutComponent
method doesn't belong to LayoutManager
: thus, you have to know and be sure that your layout
is an actual BorderLayout
.
Upvotes: 4