简体   繁体   English

Swing中的代码完成和语法突出显示

[英]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

使用JTextField作为AutoSugesstor

and for other JTextComponent s ie JTextPane , JEditorPane etc its shown at the current caret index: 对于其他JTextComponentJTextPaneJEditorPane等,它显示在当前的插入符号索引中:

在此输入图像描述

To change text colour of words (ie syntax highlight) have a look here : 要更改单词的文本颜色(即语法高亮),请查看此处

在此输入图像描述

Or if you want rather a highlighted word. 或者如果你想要一个突出显示的单词。 See here : 看到这里

在此输入图像描述

如果他们的许可条款适合您的使用案例,您可以查看来自jintilla (广泛使用的scintilla周围的JNI包装 )或jedit的组件

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

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