开发者

Looking for a way to highlight specific words in textareas?

Hi i'm looking for a way to highlight specific words in text kind of like how a text editor might work with syntax highlighting. The highlighting will consist of the text being different colours and/or different styles such as italic, bold or regular.

In order to na开发者_如何学JAVArrow focus, how this might be achieved using Java Swing components.

There are most probably a number of ways of doing this but one that is efficient in dealing with multiple highlighted words and large amounts of text.

Any feedback is appreciated. Thanks.


You can use the Highlighter that is available through JTextComponent's setHighlighter().


Have a look at Java's JEditorPane class: it does what you want.


I would use a JTextPane. Its easier to use than a JEditorPane as you don't have to know or worry about HTML. The link you where given to the Swing tutorial covers both components.


You probably need something like RSyntaxTextArea. I personally like it because: - it's easy extendable - it comes with really useful plugins - opensource & free & maintained - it supports bunch of languages like: C, Java, Ruby, Php, HTML, CSS, Sql and so on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜