next Non Alphabetic in Swing Document - Java javax.swing.text

Java examples for javax.swing.text:StyledDocument

Description

next Non Alphabetic in Swing Document

Demo Code


import javax.swing.text.*;
import java.util.*;
import javax.swing.JTextPane;
import java.awt.Color;

public class Main{
    public static int nextNonAlphabetic(Document doc, int position) {
        try {/*from   w  w  w  .j  av a2  s  . co m*/
            while (position < doc.getLength()
                    && (isLetter(doc.getText(position, 1).charAt(0)))) {
                position++;
            }
            ;
        } catch (BadLocationException ex) {
            DocUtils.writeMsg("BadLocationException in nextAlphabetic "
                    + position);
            ex.printStackTrace();
            System.exit(1);
        }
        ;

        return position;

    }
    public static boolean isLetter(char c) {
        return (Character.isAlphabetic(c) || (c == '\''));
    }
    public static void writeMsg(String msg) {
        JTextPane pane;
        Document doc;
        pane = TurkEditor.turkEditor.msgArea;
        doc = pane.getDocument();
        try {
            doc.insertString(doc.getLength(), msg + "\n", null);
        } catch (BadLocationException blex) {
        }

        pane.setCaretPosition(doc.getLength());

    }
}

Related Tutorials