RT
解决方案 »
- eclipse可否像VS一样输入一行代码回车后自动在运算符两侧加上空格,自动格式化
- 无法访问新浪??急!!!
- java.lang.RuntimeException: Uncompilable source code问题
- JAVA label标签数组的问题
- 请教关于包的导入import java.util.*和import java.util.Iterator
- 谁能给个getMethod invoke的参数说明,E文不好,看半天JDK没看明白!
- 怎么用JAVA声称50以内不重复的随机数
- protected权限问题:子类竟然不能创建父类对象调用父类的protected方法!!??
- 编译安装hadoop-2.5.0-rc1,程序包com.sun.javadoc不存在
- 关于Mac配置JDK以及环境变量问题
- ●将"Thu, 15 Jun 2006 03:38:43 GMT"转为日期型??
- 有些网页是用*.cfm结尾的,是什么?
JEditorPane
可以文本加图片
你可以参考jdk带的例子
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();
}
}