java初级 文本域

来源:百度知道 编辑:UC知道 时间:2024/05/29 17:29:09
import javax.swing.*;
public class wenbenyu extends JFrame
{JPanel rongqi=new JPanel();
JTextArea wby=new JTextArea("文本域",3,3);
JLabel biaoqian=new JLabel("标签");
public wenbenyu(){
//int rows=wby.getRows();
//wby.insert("向文本域输入信息:"+rows);
rongqi.add(wby);
rongqi.add(biaoqian);
this.add(rongqi);
this.setSize(300,300);
this.show();
JScrollPane gundong=new JScrollPane(wby,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
}
public static void main(String[] args)
{
wenbenyu aaaa=new wenbenyu();
}
}
//为什么没滚动条输出
123楼还是不行啊

import javax.swing.*;
public class wenbenyu extends JFrame
{JPanel rongqi=new JPanel();
JTextArea wby=new JTextArea("文本域",3,3);
JLabel biaoqian=new JLabel("标签");
public wenbenyu(){
JScrollPane gundong=new JScrollPane(wby,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
//int rows=wby.getRows();
//wby.insert("向文本域输入信息:"+rows);
rongqi.add(wby);
rongqi.add(biaoqian);
this.add(rongqi);
this.setSize(300,300);
this.show();

}
public static void main(String[] args)
{
wenbenyu aaaa=new wenbenyu();
}
}
这样试试

你加入滚动条对象这个操作应该在容器加入文本框之前,代码给你修改如下:
import javax.swing.*;
public class wenbenyu extends JFrame
{JPanel rongqi=new JPanel();
JTextArea wby=new JTextArea("文本域",3,3);
JLabel biaoqian=new JLabel("标签");
public wenbenyu(){