您的位置:首页 > 编程语言

一段带有边框说明的代码

2013-10-08 20:55 190 查看
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Jt{

public static void main(String[] args){

JFrame f=new JFrame( "JTextArea2 ");

f.setVisible(true);

f.setSize(600,400);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container contentPane=f.getContentPane();

contentPane.setLayout(new BorderLayout());

JPanel p1=new JPanel();

p1.setLayout(new GridLayout(1,1));

p1.setBorder(BorderFactory.createTitledBorder( "构造TextArea-使用GridLayout,加ScrollBar "));

JTextArea t1=new JTextArea(5,25);

t1.setTabSize(10);

t1.setFont(new Font( "标楷体 ",Font.BOLD,16));

t1.setLineWrap(true);//激活自动换行功能

t1.setWrapStyleWord(true);//激活断行不断字功能

p1.add(new JScrollPane(t1));//将JTextArea放入JScrollPane中

//这样就能利用滚动的效果看到输入超过JTextArea高度的文字.

contentPane.add(p1);



}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: