把JTextField放进了Jpanel后JTextField的位置和大小怎么设置

JPanel p1=new JPanel();
p1.setLayout(new FlowLayout());
JTextField text1=new JTextField(10);
如果此时加多一条JTextField.setBounds(8,10,12,16);
就会报错Cannot make a static reference to the non-static method setBounds(int, int, int, int) from the type Component
请问要如何设置。。。。

你这句JTextField.setBounds(8,10,12,16);其实就是调用JTextField类的静态方法的意思,但是这个类的这个方法不是静态的,所以出错。
不是静态的方法必须有对象才能调用,所以你应该新建一个对象。
不过,我想你应该是想让text1用这个方法,所以改成text1.setBounds(8,10,12,16);就行了~~
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答