我想创建一个具有确定大小的 jtext 字段,但我希望它在输入增长时像滚动窗格一样扩展。这是我到目前为止所拥有的:
JButton b,b1;
JLabel j1,j2,j3;
JTextField t1,t2;
public Window(){
super("frame");
//new Thread(this).start();
b=new JButton("Click");
j1=new JLabel("VALUE1");
t1=new JTextField(30);
j2=new JLabel("VALUE2");j3=new JLabel(" ");
t2=new JTextField(30);
j1.setBounds(100, 50, 150, 50);
t1.setBounds(150, 50, 200, 50);
j2.setBounds(200, 150, 250, 150);
t2.setBounds(250, 150, 200, 50);j3.setBounds(300, 150, 250, 150);
b.setBorder(new LineBorder(Color.black));
b.setBackground(Color.black);
b.setForeground(Color.white);
b1=new JButton("Exit");
super.setSize(300,300);
super.setLocation(250,150);
super.setLayout(new FlowLayout());
super.setVisible(true);
add(j1);add(t1);add(j2);add(t2); add(j3);
add(b);add(b1);
b.addActionListener(this);
b1.addActionListener(this);