For the Swing framework there is Rsyntaxtextarea who inherits from the class javax.swing.Jtextarea who uses a license derived from BSD which allows you to use the code both in open and private code and has Highlights for the following languages:
- html
- css
- java
- xml
- sql
- scala
- ruby
- python
- php
- perl
- moon
(see the full list)
An example, taken from github of the project 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 a partner and aims to add support to other languages.
I think you’ll need to put a little more detail into your question. Like, what kind of application is it (web, windows) what frameworks do you use (swing? RCP?) Just say Java gets a little vague.
– sergiopereira
True, I will change... I forget that there is not only Java Swing in the world
– Igor Costa Melo
Even for desktop still exist Javafx (the current standard); AWT,SWT, Swingx, Griffon and even the Openswing
– Mansueli
Javafx can be used together with Swing without problems?
– Igor Costa Melo
Yes, (provided you use Javafx 8). In which there is even a component called Swingnode which exists precisely to facilitate integration.
– Mansueli
I edited your topic so that it can be reopened, but I suggest you edit it again to add more information about the last sentence. For example: What would categories be? How would keywords relate to them?
– Bruno Augusto