2013-04-25 100 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組件,如文本區)。使用這兩種類型的組件可能會導致呈現問題。