Java Swing 文本字段中的 ANSI 颜色
有没有简单的方法来解析日志文件中的 Ansi 颜色,并在 Swing 的文本字段中使用它(JTextArea、JTextPAne,...)?
Is there any simple way to parse Ansi colors in log files, and use it in text fields in Swing (JTextArea, JTextPAne,...)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有尝试过,但是这里有一些代码(需要一些格式来看起来不错),它声称是 ANSI 颜色的 JTextPane 子类...
对于后代,这里是通过 NetBeans 运行以格式化代码的类
Not tried it, but there's some code here (which needs some formatting to look nice) which claims to be an ANSI colored JTextPane subclass...
For posterity, here is the class run through NetBeans to format the code
如果你的 JTextPane 是不可编辑的,那么 tim_yates 方法将不起作用,为了改进他的方法,我将他的追加方法替换为
这个方法似乎更加健壮,并且适用于我尝试过的所有情况,但我还没有测试过它完整
此方法的工作原理是在文档末尾插入彩色文本,而不是替换不存在的文本,如果它是不可编辑的,只会导致重复的 Windows 错误声音,这非常烦人
If youre JTextPane is non-editable then tim_yates method will not work, to improve upon his method I replaced his append method with
This method seems to be much more robust and works in all of the cases I have tried, but I have not tested it in full
This method works by inserting colored text at the end of the document rather than replacing text that don't exist, which if it is non-editable just results in a repeated windows error sound which is quite annoying