流水惜花吧 关注:69贴子:11,697
  • 2回复贴,共1

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.Border;
import javax.swing.text.*;
import java.io.*;
import java.text.Collator;
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, String fontFamily) {
SimpleAttributeSet attrSet = new SimpleAttributeSet();
//StyleConstants.setBackground(attrSet, col);
//颜色
if(bold==true){
StyleConstants.setBold(attrSet, true);
}//字体类型
StyleConstants.setFontSize(attrSet, fontsize);
//字体大小
StyleConstants.setForeground(attrSet, col);
StyleConstants.setFontFamily(attrSet, fontFamily);
insert(str, attrSet);
}
public void gui() {
textpane.insertIcon(image);
setDocs("第一行的文字",Color.RED,false,20,"宋体");
setDocs("第二行的文字",Color.BLUE,true,25,"宋体");
setDocs("第三行的文字",Color.GREEN,false,20,"楷体");
setDocs("abcd",Color.GREEN,false,20,"verdana");
setDocs("abcd",Color.GREEN,false,20,"verdana-bolt");
setDocs("abcd",Color.GREEN,false,20,"verdana-bold");
setDocs("abcd",Color.GREEN,false,20,"宋体");
frame.getContentPane().add(textpane );
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();
}
}


IP属地:上海1楼2011-06-30 02:46回复

    calendarPanel.addNamedCalendar(new TestNamedCalendar("Peter", "dem Peter seiner", Color.RED));
    calendarPanel.addNamedCalendar(new TestNamedCalendar("Max", "dem Max seiner", Color.BLUE));
    calendarPanel.addNamedCalendar(new TestNamedCalendar("Office", "allen ihrer", Color.GRAY));
    config
    


    IP属地:上海2楼2011-06-30 04:49
    回复
      我去,这是啥,国家机密啊


      IP属地:广东3楼2011-07-01 19:33
      回复