Source Code : Use SimpleAttributeSet with JTextPane
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Use SimpleAttributeSet with JTextPane
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
public class Main extends JTextPane {
public void appendNaive(Color c, String s) {
SimpleAttributeSet aset = new SimpleAttributeSet();
StyleConstants.setForeground(aset, c);
int len = getText().length();
setCaretPosition(len);
setCharacterAttributes(aset, false);
replaceSelection(s);
}
public static void main(String argv[]) {
Main pane = new Main();
for (int n = 1; n <= 4; n += 1) {
pane.appendNaive(Color.black, String.valueOf(n) + );
}
JFrame f = new JFrame("ColorPane example");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new JScrollPane(pane));
f.setSize(600, 400);
f.setVisible(true);
}
}
Thank with us