带语法高亮和行号的文本编辑器?

这对于一个团队项目来说有点挑战,更不用说单人实现了,但我试图使用JEditorPane将一个简单而优雅的文本编辑器与语法高亮组合在一起。 我偶然发现这个已经停止使用,我很难理解里面的所有lexer文件和.lex内容。 我甚至在一些博客中发现这个项目后来被其他一些团队采用,但甚至还没有停止。 我不需要它过于花哨,比如有代码折叠和东西(尽管我很想知道如何做到这一点),但我至少需要一个基本的语法突出显示存在和相当多的行号最左边就像Notepad ++一样。 请记住,我只需要它来突出显示Java源代码,至少目前是这样。

我正在寻找的是一个教程,一个记录良好的示例和示例代码,一个预先制作的包,甚至NetBeans的工具都可以做到这一点,我不需要从头开始编写源代码,我只需要一个可以使用的实现。 提前致谢!

PST这不是商业或太大,不要问为什么我想重新发明轮子当有那么多的编程编辑器,我正在学习,这对我来说是一个很好的练习!

RSyntaxTextArea是BSD许可的,支持您的要求,以及代码折叠等。 使用起来非常简单。

你有没有看过Netbeans的这个教程 ? 或者你检查过这个摆动组件 ?

好吧,我参与了一个类似的项目,这就是我想出来的。 到了行号,我使用了附加到实际文本窗格的滚动窗格。 然后滚动窗格使用以下代码更改数字:

 public class LineNumberingTextArea extends JTextArea { private JTextPane textArea; /** * This is the contructor that creates the LinNumbering TextArea. * * @param textArea The textArea that we will be modifying to add the * line numbers to it. */ public LineNumberingTextArea(JTextPane textArea) { this.textArea = textArea; setBackground(Color.BLACK); textArea.setFont(new Font("Consolas", Font.BOLD, 14)); setEditable(false); } /** * This method will update the line numbers. */ public void updateLineNumbers() { String lineNumbersText = getLineNumbersText(); setText(lineNumbersText); } /** * This method will set the line numbers to show up on the JTextPane. * * @return This method will return a String which will be added to the * the lineNumbering area in the JTextPane. */ private String getLineNumbersText() { int counter = 0; int caretPosition = textArea.getDocument().getLength(); Element root = textArea.getDocument().getDefaultRootElement(); StringBuilder lineNumbersTextBuilder = new StringBuilder(); lineNumbersTextBuilder.append("1").append(System.lineSeparator()); for (int elementIndex = 2; elementIndex < root.getElementIndex(caretPosition) +2; elementIndex++) { lineNumbersTextBuilder.append(elementIndex).append(System.lineSeparator()); } return lineNumbersTextBuilder.toString(); } } 

语法高亮并不是一件容易的事,但我开始的是能够根据包含某种语言的所有关键字的一些文本文件来搜索字符串。 基本上基于文件的扩展,该函数将找到正确的文件并查找该文件中包含在文本区域内的单词。