Java examples for 2D Graphics:Text
Count the line number from JTextComponent.
//package com.java2s; import javax.swing.text.Document; import javax.swing.text.JTextComponent; public class Main { /**//from ww w . ja v a2 s . c o m * Count the line number. * * @return Amount of lines. */ public static int countLines(JTextComponent txtCmp) { return countLines(txtCmp.getDocument()); } /** * Count the line number. * * @param doc JTextComponent document * @return Amount of lines. */ public static int countLines(Document doc) { return doc.getDefaultRootElement().getElementCount(); } }