2013-02-07 35 views
0

後,所以我有很大的面板:setLayout的(空)。然後我想添加按鈕。在大面板的構造函數中添加這樣的代碼:空佈局 - 組件隱藏重繪

JButton button = new JButton("eeee"); 
button.setBounds(100, 100, 100, 50); 
add(button); 

而且沒關係。但是當我重新繪製大面板按鈕隱藏。當我移動鼠標到地方,它應該是...如何防止這種奇怪的行爲再次出現?也許它與我在constrcutor中添加按鈕的事實有關?

+1

你覆蓋的方法「漆」? –

+0

是的,我喜歡。在paint方法中,我從arrayList中繪製對象 –

+0

在構造函數中做這件事很好。你確定它是一個JPanel:你沒有錯誤地使用awt.Panel?或者,你是否壓倒油漆,paintComponent等? –

回答

0

你需要讓烤漆面板組件先用「super.paint(七)」如果你不不繪製組件添加

@Override 
public void paint(Graphics g){ 
    super.paint(g); //draw your button as default 
    // hear, you can draw others things 

}