Java Syntax Highlighter is discontinued.
This library is a java port of SyntaxHighlighter, the current version ported is 3.0.83. The copyright holder of the SyntaxHighlighter is Alex Gorbatchev. It is dual licensed under the MIT and LGPL licenses. This port is written by Chan Wai Shing ([email protected]) distributed under the MIT and LGPL licenses.
- If you need an editor more than a highlighter, please find jsyntaxpane.
- I port it for Language Files Tool.
Java SE 6 or up
ActionScript3, Bash/shell, ColdFusion, C#, C++, CSS, Delphi, Diff, Erlang, Groovy, JavaScript, Java, JavaFX, Perl, PHP, Plain Text, PowerShell, Python, Ruby, Scala, SQL, Visual Basic, XML
http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/
Default, Django, Eclipse, Emacs, Fade To Grey, MD Ultra, Midnight, RDark
Click here to visit the gallery.
- Allows you to change the first (starting) line number.
- Allows you to turn gutter with line numbers on and off.
- Allows you to highlight one or more lines to focus user's attention.
- Allows you to highlight a mixture of HTML/XML code and a script which is very common in web development.
Note that this highlighter extends Swing component, so all operations are better be executed inside Swing dispatching thread.
import java.io.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import syntaxhighlight.SyntaxHighlighter;
import syntaxhighlighter.brush.*;
import syntaxhighlighter.SyntaxHighlighterParser;
import syntaxhighlighter.theme.ThemeRDark;
public class Example {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// the SyntaxHighlighter parser
SyntaxHighlighterParser parser = new SyntaxHighlighterParser(new BrushXml());
// turn HTML script on
parser.setHtmlScript(true);
// set HTML Script brushes
parser.setHTMLScriptBrushes(Arrays.asList(new BrushCss(), new BrushJScript(), new BrushPhp()));
// initialize the highlighter and use RDark theme
SyntaxHighlighter highlighter = new SyntaxHighlighter(parser, new ThemeRDark());
// set the line number count from 10 instead of 1
highlighter.setFirstLine(10);
// set to highlight line 13, 27, 28, 38, 42, 43 and 53
highlighter.setHighlightedLineList(Arrays.asList(13, 27, 28, 38, 42, 43, 53));
try {
highlighter.setContent(new File("test.html"));
} catch (IOException ex) {
Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex);
}
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(highlighter);
frame.setLocationByPlatform(true);
frame.pack();
frame.setVisible(true);
}
});
}
}