簡體   English   中英

如何獲取位於JFrame中特定布局位置的組件

[英]How do I get thet components that are in a particular layout location in JFrame

我有一個使用BorderLayoutJFrame 如何獲取此JFrame的左側或右側或任何其他位置的所有組件?

正如@brano所建議的,您可以通過JFramecontentPaneLayoutManager訪問那些組件。

例如,假設您要獲取位於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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM