For the Swing framework there is RSyntaxTextArea that inherits from the javax.swing.JTextArea using a BSD derived license which allows you to use the code in both open and private code and has highlights for the following languages:
- html
- css
- java
- xml
- sql
- scala
- ruby
- python
- php
- perl
- moon
(see full list)
One example, taken from the project's github is:
import javax.swing.*;
import org.fife.ui.rtextarea.*;
import org.fife.ui.rsyntaxtextarea.*;
public class TextEditorDemo extends JFrame {
public TextEditorDemo() {
JPanel cp = new JPanel(new BorderLayout());
RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
textArea.setCodeFoldingEnabled(true);
RTextScrollPane sp = new RTextScrollPane(textArea);
cp.add(sp);
setContentPane(cp);
setTitle("Text Editor Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
}
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new TextEditorDemo().setVisible(true);
}
});
}
}
To add new languages (your own keywords) there is this official document explaining and there is also this other project that is partner and aims to just add support for other languages .