如何使用 BorderLayout return JFrame 中心的 JPanel?

How do you return the JPanel in the center of a JFrame using a BorderLayout?

到目前为止,我发现 this post 很有帮助。

但我无法让它工作,尤其是这部分 .getLayoutComponent

这就是我希望方法在 class:

中的显示方式
public JPanel getCentrePanel() {

    return [CENTER PANEL WOULD BE RETURNED HERE];
}

您可以从 JFrame 的内容窗格中获取布局。

BorderLayout layout = (BorderLayout) frmAdmin.getContentPane().getLayout();
return (JPanel) layout.getLayoutComponent(BorderLayout.CENTER);