Swing中的代码完成和语法突出显示 [英] Code completion and Syntax Highlighting in Swing
问题描述
我已经启动了一个需要语法突出显示和代码完成的项目(在插入符号位置弹出一个提供建议的窗口),但找不到合适的解决方案。有多个Swing组件可以进行文本输入,例如JTextArea,JTextPane和JEditorPane使得确定哪个是正确使用它变得非常困难。
该项目是一个程序员特定的文本编辑器,它将与统一游戏引擎。这意味着代码完成和突出显示将在JavaScript和C#语法上完成。
这可能是显而易见的,但一般的想法是,当用户输入时,某些单词会更改为指定的颜色,这些单词将存储在文本文件中。对于代码完成,我需要能够获取当前键入的字母,此检测过程将使用空格字符作为分隔符重新启动。
感谢您的时间: )
查看我的回答:
或者如果你想要一个突出显示的单词。请参见此处:
I have started a project that requires syntax highlighting and code completion (a window pops up at the caret location providing suggestions) and can't find a suitable solution. There are multiple Swing components which take text input e.g. JTextArea, JTextPane and JEditorPane which makes it significantly more difficult to figure out which is the correct one to use.
The project is a programmer specific text editor which will have integration with the unity game engine. This meaning code completion and highlighting will be done on JavaScript and C# syntax.
It might be obvious but the general idea is that when the user types, certain words change to a specified colour, these words would be stored in a text file. For the code completion I need to be able to grab the currently typed letters, this detection process will restart by using the space character as the delimiter.
Thanks for your time :)
See my answer here which shows auto completion for JTextComponent
, it can show pop up window of auto completion words to the current caret index on JTextPane
/JEditorPane
(+1 @AndrewThompson for the idea):
For JTextField
:
and for other JTextComponent
s i.e JTextPane
, JEditorPane
etc its shown at the current caret index:
To change text colour of words (i.e syntax highlight) have a look here:
Or if you want rather a highlighted word. See here:
这篇关于Swing中的代码完成和语法突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!