[英]Code completion and Syntax Highlighting in Swing
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 eg JTextArea, JTextPane and JEditorPane which makes it significantly more difficult to figure out which is the correct one to use.
有多个Swing组件接受文本输入,例如JTextArea,JTextPane和JEditorPane,这使得确定哪个是正确的使用起来要困难得多。
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.
这意味着代码完成和突出显示将在JavaScript和C#语法上完成。
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): 请参阅我的答案,其中显示了
JTextComponent
自动完成 ,它可以显示自动完成单词的 弹出窗口到JTextPane
/ JEditorPane
上的当前插入符号索引(+1 @AndrewThompson的想法):
For JTextField
: 对于
JTextField
:
and for other JTextComponent
s ie JTextPane
, JEditorPane
etc its shown at the current caret index: 对于其他
JTextComponent
即JTextPane
, JEditorPane
等,它显示在当前的插入符号索引中:
To change text colour of words (ie syntax highlight) have a look here : 要更改单词的文本颜色(即语法高亮),请查看此处 :
Or if you want rather a highlighted word. 或者如果你想要一个突出显示的单词。 See here :
看到这里 :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.