最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Code completion and Syntax Highlighting in Swing - Stack Overflow

programmeradmin1浏览0评论

I have started a project that requires syntax highlighting and code pletion (a window pops up at the caret location providing suggestions) and can't find a suitable solution. There are multiple Swing ponents 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 pletion 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 pletion 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 :)

I have started a project that requires syntax highlighting and code pletion (a window pops up at the caret location providing suggestions) and can't find a suitable solution. There are multiple Swing ponents 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 pletion 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 pletion 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 :)

Share Improve this question asked Jan 9, 2013 at 6:38 someSortOfProgrammersomeSortOfProgrammer 1632 silver badges5 bronze badges 1
  • 6 "Thanks for your time :)" Do you have a question? If so, what is it? BTW - JTextArea is for plain text so will be unsuited to this task, whereas JTextPane and JEditorPane support styled text. – Andrew Thompson Commented Jan 9, 2013 at 6:40
Add a ment  | 

2 Answers 2

Reset to default 6

See my answer here which shows auto pletion for JTextComponent, it can show pop up window of auto pletion 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:

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

发布评论

评论列表(0)

  1. 暂无评论