JTextArea和JTextpane的转换问题!急请高手帮忙!

boaobbs2785 2008-04-10 12:08:33
将组件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);
}
}
...全文
82 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
llpgy 2008-04-10
  • 打赏
  • 举报
回复
import javax.swing.*;
import java.awt.*;
import javax.swing.text.*;

public class JTextPaneExam extends JApplet
{
JTextArea textArea;
public void init()
{
textArea =new JTextArea();
JScrollPane scroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
textArea.append("sdfsdf\n");
textArea.append("sdfsdfdfhdfhdfh\n");
getContentPane().add(scroll);
}
}

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧