怎么样设置JTextField的长度和宽度? 设置长度:textfield.setColumns(长度); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要设置长和宽,也可以textfield.setBounds(new Rectangle(30, 30, 30, 30));前两个参数是TextField在FRAME中的位置,后两个参数就是长宽大小了 还有个setSize(int hight,int weight) setSize(int hight,int weight)textfield.setBounds(new Rectangle(30, 30, 30, 30)); 我是过了没用,我用的是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"); } }} 请教有关图像的问题!icon.getIcon().getScaledInstance(参数) 十六进制转字符串乱码问题 如何用将HTML中<BODY></body>之间的值取出来? 如何是JLabel不随文字的长度而改变大小 java学习 针对按钮实现跳转页面的问题? 请教一个弱弱的问题,java怎么运行jar文件 大家帮我看看这里的JProgress哪里用错了? 怎么为JTree控件添加addTreeSelectionListener事件? 惭愧!问一个比较弱的问题。 如何在applet中产生一个对话框? ----正则表达式的问题-----
textfield.setBounds(new Rectangle(30, 30, 30, 30));
前两个参数是TextField在FRAME中的位置,后两个参数就是长宽大小了
textfield.setBounds(new Rectangle(30, 30, 30, 30));
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");
}
}
}