Code completion and Syntax Highlighting in Swing

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 01:30:24

问题


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 :)


回答1:


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 JTextComponents 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:




回答2:


you can look at components from jintilla (a JNI wrapper around the widely used scintilla) or jedit if their licensing terms fit your use case.



来源:https://stackoverflow.com/questions/14229611/code-completion-and-syntax-highlighting-in-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!