Java 回转控制不可见
Swing控件不可见。它显示一个灰色屏幕,其中没有任何组件,awt也会发生同样的情况Java 回转控制不可见,java,swing,controls,Java,Swing,Controls,Swing控件不可见。它显示一个灰色屏幕,其中没有任何组件,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(2
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();
标签未显示`
l1 = new JLabel("User Name");
getContentPane().add(p1);
setSize(350, 150);
setVisible(true);
}
public static void main(String args[]) {
new s1();
}
}
您的JLabel已创建,但未添加到任何组件,因此它不可见:
p1.add(l1);
假设您希望它显示在您的JPanel中。您永远不会添加标签。您只需将空的
JPanel
添加到JFrame