nameTextField = new JTextField();
nameTextField.setColumns(140);
final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
gridBagConstraints_1.gridy = 0;
gridBagConstraints_1.gridx = 1;
topPanel.add(nameTextField, gridBagConstraints_1);
这个是输入框的代码,运行的时候,都挤在一起了,就像一条竖线

解决方案 »

  1.   

    你给的每个组件加了位置设置了没有啊???我估计你没写。
    nameTextField.setColumns(140); 
    这样写不行。
    要写成:nameTextField.setBounds(int x,int y,组件宽度,组件高度);
     topPanel.add(nameTextField);这样写就行了,不过感觉你的代码乱糟糟的。建议你巩固一下Java基础。
      

  2.   


    用setBounds(int x,int y,组件宽度,组件高度);一般要topPanel.setLayout(null);下才用
      

  3.   

    嗯,楼上提的好,,我忘了说了,你把你的容器组件布局改成null布局就可以了。
      

  4.   

    一般都会有默认布局,如果你 想让组件按你的意愿拜访,就先把布局设为null
      

  5.   

    看是不是应该把panel放在frame里面,实在不行就使用setBounds进行布局