学习swing时练手写了一段代码
运行时jframe可以运行,但是panel中却无法加载那个文本框,请问这是为什么呢
很不理解,我检查了很长时间都不知道哪错了
先建了一个对象panel,然后通过setContentPane设置panel为中间容器,之后add
加载,甚至我还对照了几个范本,也没找出错误在哪
public static void main(String[] args) {
JFrame frame1 = new JFrame();
frame1.setLayout(null);
frame1.setBounds(0, 0, 450, 350);
frame1.setResizable(false);
frame1.setLocationRelativeTo(null);
frame1.setVisible(true);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame1.setContentPane(panel);
JTextField text = new JTextField(17);
text.setBounds(100, 100, 150, 20);
panel.add(text,BorderLayout.SOUTH);
}