2013-07-04 49 views
0

擺動控制不可見。它顯示一個沒有任何組件的灰色屏幕,同樣的事情發生在awt?擺動控制不可見

import javax.swing.*; 

public class s1 extends JFrame { 

JLabel l1, l2; 
JTextField t2; 
JButton b1, b2; 
JPanel p1; 

public s1() { 


    setTitle("Login Window");`setting title for the Window ` 
    setBounds(200, 200, 350, 150); `setting boundations for window` 
    p1 = new JPanel(); 

標籤不displayed`

l1 = new JLabel("User Name"); 
getContentPane().add(p1); 
setSize(350, 150); 
setVisible(true); 
} 

public static void main(String args[]) { 
    new s1(); 

} 
} 
+0

你永遠不會添加你的標籤。您只需在JFrame中添加一個空的'JPanel' – Robin

回答

1

你的JLabel已經建立,但沒有添加任何成分,所以它是不可見的:

p1.add(l1); 

假設你想讓它將顯示在您的JPanel中。