2013-04-25 107 views
0
JTabbedPane main_tabbedPane = new JTabbedPane(JTabbedPane.TOP); 
main_tabbedPane.setBorder(new EmptyBorder(0, 0, 0, 0)); 
main_tabbedPane.setBounds(10, 76, 665, 473); 
main_tabbedPane.setVisible(false); 

main_content.add(main_tabbedPane); // main_content is a jpanel 

我然后调用该扩展JPanelAWT文本区域

alphaStarter_tab = new AlphaStarterPnl(); 

其中除其他外有一个文本区域(从Java AWT没有的JTextArea)

public class AlphaStarterPnl extends JPanel { 

private TextArea outputTxtA; 

public AlphaStarterPnl(){ 

    outputTxtA = new TextArea("",4,50,TextArea.SCROLLBARS_VERTICAL_ONLY); 
    outputTxtA.setFont(new Font("Tahoma", Font.PLAIN, 13)); 
    outputTxtA.setEditable(false); 
    outputTxtA.setBackground(new Color(179,190,201)); 
    outputTxtA.setForeground(new Color(34,64,132)); 
    outputTxtA.setBounds(15, 133, 630, 300); 
    add(outputTxtA); 

} 
} 

我一类的构造函数然后添加此面板(其中有更多的比它粘贴的代码,但这并不重要)到选项卡窗格

main_tabbedPane.addTab("Copy Files", null, alphaStarter_tab, null); 

当我这样做时,尽管main_tabbedPane已被设置为setvisible false,TextArea弹出,不仅如此,但它也出现在三个地方。 (也许在0,0坐标上出现一次,然后在x,0坐标上,然后在x,y坐标上出现。当我继续执行程序时,当第二个选项卡是“补充说。

有什么想法?

+1

不要使用TextArea。使用JTextArea。不要使用setBounds()。使用合适的布局管理器。 – camickr 2013-04-25 19:34:56

回答

0

这里的问题可能是,你是混合轻量级组件(即Swing组件一样JTabbedPane中,那些具有“J”字头)和重量级组件(即AWT组件,如文本区)。使用这两种类型的组件可能会导致呈现问题。