Here you can find the source of getParagraphElement(JTextComponent c, int offs)
Parameter | Description |
---|---|
c | the editor |
offs | the starting offset in the document >= 0 |
public static final Element getParagraphElement(JTextComponent c, int offs)
//package com.java2s; /*/*from w ww . ja v a2 s. c o m*/ * @(#)Utilities.java 1.40 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import javax.swing.text.*; public class Main { /** * Determines the element to use for a paragraph/line. * * @param c the editor * @param offs the starting offset in the document >= 0 * @return the element */ public static final Element getParagraphElement(JTextComponent c, int offs) { Document doc = c.getDocument(); if (doc instanceof StyledDocument) { return ((StyledDocument) doc).getParagraphElement(offs); } Element map = doc.getDefaultRootElement(); int index = map.getElementIndex(offs); Element paragraph = map.getElement(index); if ((offs >= paragraph.getStartOffset()) && (offs < paragraph.getEndOffset())) { return paragraph; } return null; } }