JTabbedPane 组件的选项卡未显示

JTabbedPane component's tabs not showing up

鉴于 JFrame 的 contentPane 布局设置为空,我想添加两个选项卡,一个用于发布者,另一个用于订阅者,例如:

public class PubSubGUI extends JFrame{
   private JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
   private JPanel pubPanel = new JPanel();
   private JPanel subPanel = new JPanel();  
   public PubSubGUI(Controller controller) {
         getContentPane().setLayout(null);
         getContentPane().add(tabbedPane);
         //add Publisher components to pubPanel
         tabbedPane.addTab("Publlisher", pubPanel);         
         //add Subscriber components to pubPanel
         tabbedPane.addTab("Subscriber", subPanel);
         //Rest of the constructor's source code is omitted
   }
   //Rest of the class' source code is omitted
}

当 运行 时,应用程序既不显示组件也不显示选项卡。我得到的只是一个空 JFrame。我尝试为 pubPanelsubPanel 分别设置不同的 LayoutManager,问题仍然存在。请有任何提示或建议。

参考这个:

import javax.swing.*;  
public class TabbedPaneExample {  
JFrame f;  
TabbedPaneExample(){  
    f=new JFrame();  
    JTextArea ta=new JTextArea(200,200);  
    JPanel p1=new JPanel();  
    p1.add(ta);  
    JPanel p2=new JPanel();  
    JPanel p3=new JPanel();  
    JTabbedPane tp=new JTabbedPane();  
    tp.setBounds(50,50,200,200);  
    tp.add("main",p1);  
    tp.add("visit",p2);  
    tp.add("help",p3);    
    f.add(tp);  
    f.setSize(400,400);  
    f.setLayout(null);  
    f.setVisible(true);  
}  
public static void main(String[] args) {  
    new TabbedPaneExample();  
}}