Example usage for javax.swing.text Segment first

List of usage examples for javax.swing.text Segment first

Introduction

In this page you can find the example usage for javax.swing.text Segment first.

Prototype

public char first() 

Source Link

Document

Sets the position to getBeginIndex() and returns the character at that position.

Usage

From source file:LiveParenMatcher.java

public void insertUpdate_3(DocumentEvent de) {
    Document doc = de.getDocument();
    int offset = de.getOffset();
    int length = de.getLength();
    Segment seg = new Segment();
    try {//ww w.j a va  2 s.  com
        doc.getText(offset, length, seg); // text placed in Segment
    } catch (BadLocationException ble) {
    }

    // iterate through the Segment
    for (char ch = seg.first(); ch != seg.DONE; ch = seg.next())
        if (ch == '(' || ch == '[' || ch == '{' || ch == ')' || ch == ']' || ch == '}') {
            SwingUtilities.invokeLater(this); // will call run()
            return; // no need to check further
        }
}