不可以吧?JTextArea只支持纯文本。可以用JEditorPane实现你的要求。
解决方案 »
- 关于在继承中当需要使用父类的属性时为什么需要在子类的构造器中使用?
- 双向的冒泡法有点bug
- 请问这个类在api里怎么没有帮助文档呀,那他的文档在哪sun.audio.AudioStream
- xml问题,难倒没人会,我发了还多帖子了。都是无满意结贴。
- 如何在客户端方判断socket连接是否关闭
- 请问用appletviewer看html时,appletviewer显示APPLET没有初始化,该如何解决?(.java文件已通过编译)
- 怎样用JAVA在B/S结构下实现二个服务器之间的文件交换
- 各位,我问个很菜的问题。
- 看里面代码??
- 正则表达式的效率比String.split更低吗?
- how to compile java package????
- 请问在JBuilder9中部署ejb时怎么修改weblogic-ejb-jar.xml文件?
我还是希望有高手指点用JTextArea实现我要求的功能!!!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.text.*;
import java.io.*;public class Test {
JFrame frame;
JTextPane textPane;
File file;
Icon image; public Test(){
frame = new JFrame("JTextPane");
textPane = new JTextPane();
file = new File("./classes/test/icon.gif");
image = new ImageIcon(file.getAbsoluteFile().toString());
} public void insert(String str, AttributeSet attrSet) {
Document doc = textPane.getDocument();
str ="\n" + str ;
try {
doc.insertString(doc.getLength(), str, attrSet);
}
catch (BadLocationException e) {
System.out.println("BadLocationException: " + e);
}
} public void setDocs(String str,Color col,boolean bold,int fontSize) {
SimpleAttributeSet attrSet = new SimpleAttributeSet();
StyleConstants.setForeground(attrSet, col);
//颜色
if(bold==true){
StyleConstants.setBold(attrSet, true);
}//字体类型
StyleConstants.setFontSize(attrSet, fontSize);
//字体大小
insert(str, attrSet);
} public void gui() {
textPane.insertIcon(image);
setDocs("第一行的文字",Color.red,false,20);
setDocs("第二行的文字",Color.BLACK,true,25);
setDocs("第三行的文字",Color.BLUE,false,20);
frame.getContentPane().add(textPane, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}});
frame.setSize(200,300);
frame.setVisible(true);
}
public static void main(String[] args) {
Test test = new Test();
test.gui();
}
}
<------ 树欲静而风不止 ------>