Java examples for javax.swing.text:StyledDocument
next Non Alphabetic in Swing Document
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()); } }