[英]How do I get thet components that are in a particular layout location in JFrame
我有一個使用BorderLayout
的JFrame
。 如何獲取此JFrame
的左側或右側或任何其他位置的所有組件?
正如@brano所建議的,您可以通過JFrame
的contentPane
的LayoutManager
訪問那些組件。
例如,假設您要獲取位於BorderLayout.WEST
上的組件(並且您的JFrame
稱為frame
),則可以執行以下操作:
final BorderLayout layout = (BorderLayout) frame.getContentPane().getLayout();
final Component west = layout.getLayoutComponent(BorderLayout.WEST);
不過請注意: getLayoutComponent
方法不屬於LayoutManager
:因此,您必須知道並確保您的layout
是實際的BorderLayout
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.