0

Swing controls are not visible.It displays a Grey screen without any components in it,Same thing is happening with 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();

Label not displayed`

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

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

}
}
4

1 回答 1

1

您的 JLabel 已创建,但未添加到任何组件,因此它不可见:

p1.add(l1);

假设您希望它显示在您的 JPanel 中。

于 2013-07-04T15:03:26.117 回答