Menu

Tutorial

Clemens Renner
Attachments
Jyntax-demo.jpg (8521 bytes)

If you don't have Jyntax available in your project yet, see the [Installation] page first.

A simple usage example

Consider the example Java code available via the Jyntax revision control system.

It displays a simple frame with one text area and a Jyntax highlighter attached that has one highlighting rule. Particularly interesting with respect to the usage of Jyntax is the following part:

// set up the highlighter with a simple rule
SimpleSyntaxHighlighter hl = new SimpleSyntaxHighlighter(textComp);
HighlightRule rule = new HighlightRule("[a-z][0-9][A-Z]", "[0-9]");
hl.addRule(rule);

This is where you create the default implementation of the JyntaxHighlighter, the SimpleSyntaxHighlighter. What follows next is the creation of a simple HighlightRule. The rule says:

Whenever you find a number from 0 to 9, enclosed by a lower case letter on the left and an upper case letter on the right, highlight the number.

The first argument to the HighlightRule constructor is called the pattern.
It is used to find parts of the text that should be highlighted.
The second argument to the constructor is called a token.
It tells the highlighter which part of the pattern it should paint with a color.

The patterns and the tokens are expressed using the Java Regular Expression mechanism that is documented quite nicely in the Pattern Java class API.


Related

Wiki: Installation
Wiki: Main_Page

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.