JEditor editor = new JEditor(); editor.setSyntax("xml"); SyntaxListener listener = new SyntaxListenerImpl(); editor.setSyntaxListener(listener);
public class SyntaxListenerImpl implements SyntaxListener { private SyntaxDocument document; private boolean updated = false; public SyntaxListenerImpl() { } @Override public void documentUpdated(SyntaxDocument document) { this.document = document; updated = true; } public void tokenize() { if (updated) { document.tokenizeLines(); // call the tokenization of the document updated = false; } } @Override public void startToken(int lineIndex, int offset, Token token) { String message = "[lineIndex: " + lineIndex + ", offset:" + offset + ", token:" + token.getTokenName() + ", length:" + token.length + " : " + document.getTextProtected(offset, token.length) + "]"; System.out.println(message); } }
Copyright 2016-2019 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence