怎么样设置JTextField的长度和宽度?
JTextField的宽度和长度如何设置? 问题点数:10、回复次数:10Top
1 楼charmgjj(杰)回复于 2004-08-01 23:18:45 得分 0
各位大哥帮忙up一下呗!!!Top
2 楼charmgjj(杰)回复于 2004-08-01 23:48:00 得分 0
自己up一下!!!!!Top
3 楼swiminthesea(发展才是硬道理)回复于 2004-08-02 00:46:10 得分 2
设置长度:
textfield.setColumns(长度);Top
4 楼swiminthesea(发展才是硬道理)回复于 2004-08-02 00:53:55 得分 2
要设置长和宽,也可以
textfield.setBounds(new Rectangle(30, 30, 30, 30));
前两个参数是TextField在FRAME中的位置,后两个参数就是长宽大小了Top
5 楼hulun(天涯)回复于 2004-08-02 06:57:00 得分 2
还有个setSize(int hight,int weight)Top
6 楼accpdeng(云游天下)回复于 2004-08-02 08:29:36 得分 2
UP
Top
7 楼eaglecoody(小虾米)回复于 2004-08-02 09:21:54 得分 2
setSize(int hight,int weight)
textfield.setBounds(new Rectangle(30, 30, 30, 30));
Top
8 楼charmgjj(杰)回复于 2004-08-02 21:36:42 得分 0
我是过了没用,我用的是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");
}
}
}Top
9 楼charmgjj(杰)回复于 2004-08-02 23:03:10 得分 0
谢谢各位,帮忙up一下呗!!!Top
10 楼charmgjj(杰)回复于 2004-08-03 20:49:05 得分 0
先多谢各位了帮忙up一下Top
相关问题
- 怎样设置Grid的长度和宽度?????
- DataGrid控件如何设置其宽度自动适应数据库数据的长度?
- 怎样得到在属性里没有设置图片长宽的图片的长度和宽度
- <table>栏宽度的设置?
- 我要在单文档中实现打印,但不知如何实现打印纸大小的设置。(比方说给定长度和宽度)。
- $$$如何设置iframe的长度和宽度,使它能自适应src中引导过来的页面,而不出现scroll bar???
- 请问怎样实现在网页中弹出“网页对话框”,并能够设置对话框的长度和宽度?
- 请问怎样实现在网页中弹出“网页对话框”,并能够设置对话框的长度和宽度?
- 用pb数据窗口下再一个嵌套式报表做为资料打印,这样当调整grid宽度时怎样得到report的所有列的总长度然后设置表头的长度?
- 怎样设置checklistbox每列的宽度?




