设置长度:
textfield.setColumns(长度);

解决方案 »

  1.   

    要设置长和宽,也可以
    textfield.setBounds(new Rectangle(30, 30, 30, 30));
    前两个参数是TextField在FRAME中的位置,后两个参数就是长宽大小了
      

  2.   

    还有个setSize(int hight,int weight)
      

  3.   

    setSize(int hight,int weight)
    textfield.setBounds(new Rectangle(30, 30, 30, 30));
      

  4.   

    我是过了没用,我用的是JTextField,各位帮小弟看看
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class lending extends JFrame implements ActionListener {
    JLabel lbltitle,lblname,lblpassword,l1,l2,l3,l4;
    JTextField txtname;
    JPanel p1,p2,p3;
    JPasswordField txtpassword;
    JButton cmdenter,cmdexit;
    lending(){
    // System.out.println("lili");
    lbltitle=new JLabel("欢迎使用本系统 ");
    lblname=new JLabel("姓名:",SwingConstants.RIGHT);
    lblpassword=new JLabel("密码:",SwingConstants.RIGHT);
    txtname=new JTextField(30);
    txtname.setSize(20,50);
    txtname.setBounds(new Rectangle(10,50,30,30));
    txtpassword=new JPasswordField(30);
    txtpassword.setEchoChar('#');
        l1=new JLabel();
    l2=new JLabel();
    l3=new JLabel();
    l4=new JLabel();
    p1=new JPanel();
    p2=new JPanel();
    p3=new JPanel();
    cmdenter=new JButton(" 确 定 ");
    cmdexit=new JButton(" 退 出 ");
    this.getContentPane().setForeground(Color.blue);
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(p1,BorderLayout.NORTH);
    this.getContentPane().add(p2,BorderLayout.CENTER);
    getContentPane().add(p3,BorderLayout.SOUTH);
    // getContentPane().add(new JScrollPane(txts));
    Font f1=new Font("fmi",Font.BOLD+Font.ITALIC,20);
    p1.add(lbltitle);
    lbltitle.setFont(f1);
    lbltitle.setForeground(new Color(127,122,235));
    Font f=new Font("ff",Font.PLAIN,15);
    p2.setLayout(new GridLayout(3,3,10,20));
    lblname.setForeground(Color.blue);
    lblname.setFont(f);
    p2.add(lblname);
    p2.add(txtname);
    p2.add(l1);
    cmdenter.addActionListener(this);
    cmdexit.addActionListener(this);
    lblpassword.setForeground(Color.blue);
    lblpassword.setFont(f);
    p2.add(lblpassword);
    p2.add(txtpassword);
    p2.add(l2);
    p2.add(l3);
    p2.add(l4);
    cmdenter.setForeground(Color.blue);
    cmdenter.setFont(f);
    p3.add(cmdenter);
    cmdexit.setForeground(Color.blue);
    cmdexit.setFont(f);
    p3.add(cmdexit);
    this.setSize(300,200);
    this.setTitle("地址簿登陆");
    this.show(true);
    }
    public static void main(String args[]){
    lending l=new lending();
    } public void actionPerformed(ActionEvent e) {
    // TODO: Add your code here
    Object obj=e.getSource();
    if (obj==cmdenter){
    txtname.setText("你好");
    txtpassword.setText("000");
    }
    else{ 
    txtname.setText("error");
    txtpassword.setText("99999");
    }
    }
    }