views:

519

answers:

5

There are many tutorials online giving very complex or non-working examples on this. It seems that people recommend others to use the syntax highlighters offered by netbeans but I am totally puzzled on how to do so!

I have checked many many sites on this and the best I can find is : http://www.antonioshome.net/kitchen/netbeans/nbms-standalone.php

However I am still not able to use this example (as it is aimed to people who don't want to use the Netbeans platform but just a portion of it) and I am still not sure if I can just use syntax highlighting in a simple plug 'n play way. For example netbeans supports several language highlights by default, can I just use the highlighters in a JEditorPane to parse Ruby/Python/Java for example ? or do I need to write my own parser :-| ?

I will really appreciate a small simple example on how to plug syntax highlight in a standalone application using the netbeans platform.

A: 

Partial Answer :

Apparently the following will enable syntax highlighting for Java (and some code completion) however it does not seem to work for other languages (except java, XML) even though it should [1]. Also I cannot find any way of enabling line numbers (they are enabled but they don't show up)!

yourEditor.setContentType("text/x-java");
yourEditor.putClientProperty("HighlightsLayerIncludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.SyntaxHighlighting$");

If someone decides to help with this, a more unified example including line numbers and other properties will be good. Surely it shouldn't be really complex ?!?

[1] http://netbeans.sourcearchive.com/lines/6.5-0ubuntu2/CodeTemplatesPanel_8java-source.html

Volta
A: 

Comments seems to be disabled. Did you ever get this sorted out? Did you decide to go with a different editor? Currently I'm working with the editor from jEdit, which is ok, but I was trying to get some of the more advanced features out of the netbeans editor. I ran into the same problems. I'm curious if/how you solved it.

Lonnen
No, I have been looking for information and examples on the Editor API as well, no examples anywhere. This is really bizarre! most other futures are very well documented except anything to do with editors.
Volta
A: 

This is how I use it:

String mimeType = "text/x-java"; // NOI18N
JEditorPane editorPane = new JEditorPane();

editorPane.setEditorKit(MimeLookup.getLookup(mimeType).lookup(EditorKit.class));
JB
A: 

To get line numbers you can use the following snippet:

BaseTextUI eui = new BaseTextUI();
eui.installUI(editor);
panel.add(eui.getEditorUI().getExtComponent());
Roman Timushev

related questions