如何通过 JEditorPane 使用 Netbeans 平台语法突出显示?
网上有很多教程提供了非常复杂或不起作用的示例。似乎人们推荐其他人使用 netbeans 提供的语法荧光笔,但我完全不知道如何做到这一点!
我已经检查了很多关于此的网站,我能找到的最好的是: http://www.antonioshome.net/kitchen/netbeans/nbms-standalone。 php
但是我仍然无法使用这个示例(因为它是针对那些不想使用 Netbeans 平台而只是其中一部分的人),并且我仍然不确定是否可以 只需以简单的即插即用方式使用语法突出显示即可。例如netbeans支持 默认情况下有多种语言突出显示,例如,我可以使用 JEditorPane 中的突出显示来解析 Ruby/Python/Java 吗?或者我需要编写自己的解析器:-| ?
我非常欣赏一个关于如何使用 netbeans 平台在独立应用程序中插入语法突出显示的小简单示例。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这就是我的使用方式:
This is how I use it:
你好,
如果你试图做一个独立的平台应用程序,我发现类似的缺乏信息,最后这就是我在自己的应用程序中所做的,是的,它可能是重新发明轮子..但因为我找不到轮子首先,不妨创建一个..
我在这里获取了有关如何创建 java 编辑器套件的信息:
http://java.sun.com/products/jfc /tsc/articles/text/editor_kit/index.html
使用必要的文件构建了一个小包,并将其拉入我的平台应用程序的其中一个模块下。您将需要 tools.jar,其中隐藏了所有扫描仪位,它位于 JDK install /lib 文件夹下 - 您必须将其包装起来。
然后使用测试程序中的示例来弄清楚如何设置样式,-我喜欢您对令牌着色的完全控制。
无耻地从包含的 JavaKitTest 中复制..
这只是一个 java 扫描仪,当然通过这个示例,您可以尝试使用语法和标记并提出您自己的规则,我认为有关于所有这些东西的教程..
希望这会有所帮助。
Hallo,
I found similar lack of info if you're trying to do a standalone platform app, in the end here is how I did it in my own application, yes it might be reinventing the wheel.. but since I couldnt find the wheel in the first place, might as well create one..
I took the information on how to create a java editor kit here:
http://java.sun.com/products/jfc/tsc/articles/text/editor_kit/index.html
Built a small package with the necessary files, and pulled it into my platform application under one of the modules. You will need tools.jar where all those Scanner bits are hiding, it lives under the JDK install /lib folder - you'll have to wrap that.
Then used the example in the test program to figure out how to set the styles, - I like the complete control you have over token colouration.
Shamelessly copied from the included JavaKitTest..
This is just a java scanner, of course with this example you can get to play around with the grammar and tokens and come up with your own rules, I think there are tutorials on all that stuff..
Hope this helps a bit.
部分答案:
显然,以下内容将为 Java 启用语法突出显示(以及一些代码完成),但它似乎不适用于其他语言(java、XML 除外),尽管它应该 [1]。另外,我找不到任何启用行号的方法(它们已启用但不显示)!
如果有人决定提供帮助,那么包含行号和其他属性的更统一的示例将会很好。当然它不应该很复杂?!?
[1] http://netbeans.sourcearchive.com/lines/6.5 -0ubuntu2/CodeTemplatesPanel_8java-source.html
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)!
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
下面应该为您提供 javascript 的语法突出显示。查找其他类型的哑剧以使用不同的语法。
The following should give you syntax highlighting for javascript. Find mimes for other types to use different syntax.
要获取行号,您可以使用以下代码片段:
To get line numbers you can use the following snippet: