简体   繁体   English

JTextPane不可变文本块

[英]JTextPane immutable text blocks

I've been creating something like text editor for a while and noticed one interesting feature in NetBeans: when creating Java Application from a template (for example, "Desktop Application"), it creates immutable blocks of code (they are present for viewing but they can not be modified directly). 我一直在创建类似文本编辑器的东西,并注意到NetBeans中有一个有趣的功能:从模板创建Java应用程序时(例如,“桌面应用程序”),它会创建不可变的代码块(它们可供查看但是它们不能直接修改)。

This shot should make all that text above clear: 此镜头应使上述所有文字清晰:

在此输入图像描述

So, the question is: how to implement such a feature using JTextPane? 那么,问题是:如何使用JTextPane实现这样的功能?

You must create a class implementing the javax.swing.text.DocumentFilter used by your editor pane for the unchanged text. 您必须创建一个实现编辑器窗格用于未更改文本的javax.swing.text.DocumentFilter的类。 For the highlighting I suppose you will have to use a javax.swing.text.Highlighter. 为了突出显示,我想你将不得不使用javax.swing.text.Highlighter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM