使用JTextPane代替JTextArea实现每一行的字的颜色不一样
来源:互联网 发布:手机剪切mp3软件 编辑:程序博客网 时间:2024/05/21 14:58
import java.awt.BorderLayout;import java.awt.Color;import javax.swing.JFrame;import javax.swing.JScrollPane;import javax.swing.JTextPane;import javax.swing.text.BadLocationException;import javax.swing.text.Style;import javax.swing.text.StyleConstants;public class TestJTextPane extends JFrame { private JTextPane textPane = new JTextPane(); public TestJTextPane () { this.add(new JScrollPane(textPane), BorderLayout.CENTER); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(800, 600); this.setLocationRelativeTo(null); Style def = textPane.getStyledDocument().addStyle(null, null); StyleConstants.setFontFamily(def, "verdana"); StyleConstants.setFontSize(def, 12); Style normal = textPane.addStyle("normal", def); Style s = textPane.addStyle("red", normal); StyleConstants.setForeground(s, Color.RED); textPane.setParagraphAttributes(normal, true); for(int i=0; i<1000; i++){ try { textPane.getDocument().insertString(textPane.getDocument().getLength(), "hello, ", textPane.getStyle(i%2 == 0 ? "red" : "normal")); } catch (BadLocationException e1) { } } } public static void main(String[] args) { new TestJTextPane().setVisible(true); }}
- 使用JTextPane代替JTextArea实现每一行的字的颜色不一样
- jtextarea jedtorpane jtextpane jtextfield的区别
- 为CListCtrl每一行设置不同的颜色
- VC 中改变ListCtrl每一行的文字颜色
- 让ListBox控件每一行显示不同的颜色
- 如何更好的使用JTextPane
- JTextArea的简单使用
- 不一样的颜色对比
- 按条件控制dbgrid每一行的颜色(3种以上的颜色)
- c++实现对每一行输入的数据的运算
- JTextArea比较详细的使用
- JTextPane的例子,模拟聊天客户端,演示了为每段文字设置字体、字号、样式、颜色、背景色和插入图片功能
- 使用Java中JTextArea实现类似命令行操作的界面
- 显示每一行的序号
- 数据库每一行的长度
- SQL 2005中实现循环每一行做的操作
- C实现读取文件的每一行 并标号
- listview每一行显示不一样的控件!已更新,原来的有点儿小问题,会在内容中指明!
- linux socket
- 客户能从CRM中得到什么好处?
- C#中索引提供[ ] 类的语法
- 网页有误 没有弹出alter()提示框
- How to initialize current row for richface Datatable
- 使用JTextPane代替JTextArea实现每一行的字的颜色不一样
- 视图分割与视图间通信资料汇总!
- UITableView 基本使用方法总结
- Struts2 的简介
- 关于MATLAB的GUI一些实用小技巧
- iOS开发笔记:导航栏里的"Back"按钮显示不出来
- demo05_atomic、nonatomic、assign、retain、copy
- Android ApiDemos示例解析(60):Graphics->ColorMatrix
- Winscape虚拟窗景结合Kinect:窗前可观看巴厘岛海景