JTabbedPane 组件的选项卡未显示



给定一个内容窗格的布局设置为 null 的JFrame,我想添加两个选项卡,一个用于发布者,另一个用于订阅者,例如:

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();  
}}   

最新更新