문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top