JTextArea和JTextpane的转换问题!急请高手帮忙!
将组件JTextPane 换成JTextArea ;即将读取的文件信息在JTextArea 中显示,该如何修改? 谢谢高手了
import javax.swing.*;
import java.awt.*;
import javax.swing.text.*;
public class JTextPaneExam extends JApplet{
JTextPane textpane;
MutableAttributeSet center_align,char_style_1,char_style_2;
public void init(){
textpane=new JTextPane();
JScrollPane scroll=new JScrollPane(textpane,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
Document mydocument=textpane.getDocument();//初始化文档
center_align=new SimpleAttributeSet();
char_style_1=new SimpleAttributeSet();
char_style_2=new SimpleAttributeSet();
//设置文本属性对象对齐方式
StyleConstants.setAlignment(center_align,StyleConstants.ALIGN_CENTER);
//设置文本属性对象1的属性
StyleConstants.setFontFamily(char_style_1,"Courier");
StyleConstants.setFontSize(char_style_1,20);
StyleConstants.setForeground(char_style_1,Color.red);
//设置文本属性对象2的属性
StyleConstants.setFontFamily(char_style_2,"Serif");
StyleConstants.setFontSize(char_style_2,14);
StyleConstants.setForeground(char_style_2,Color.blue);
//设置文本面板段落的属性
textpane.setParagraphAttributes(center_align,true);
textpane.setCharacterAttributes(char_style_1,true);
try{textpane.insertIcon(new ImageIcon("a.jpg"));
mydocument.insertString(mydocument.getLength(),"Lovely Watermelon\n",char_style_1);
}
catch(BadLocationException e){}
//设置文本面板段落的属性
textpane.setParagraphAttributes(center_align,true);
textpane.setCharacterAttributes(char_style_2,true);
try{
mydocument.insertString(mydocument.getLength(),"I Want It\n",char_style_2);
}
catch(BadLocationException e){}
getContentPane().add(scroll);
}
}