Java JTextComponent getParagraphElement(JTextComponent c, int offs)

Here you can find the source of getParagraphElement(JTextComponent c, int offs)

Description

Determines the element to use for a paragraph/line.

License

Open Source License

Parameter

Parameter Description
c the editor
offs the starting offset in the document >= 0

Return

the element

Declaration

public static final Element getParagraphElement(JTextComponent c, int offs) 

Method Source Code

//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;
    }
}

Related

  1. ensureCustomBackgroundStored(JTextComponent comp)
  2. fillWith(String value, JTextComponent... fields)
  3. getAdjustedClickCount(JTextComponent comp, MouseEvent e)
  4. getCurrentTextBlock(JTextComponent textComponent)
  5. getNumberOfLines(final JTextComponent component)
  6. getPositionBelow(JTextComponent c, int offs, int x)
  7. getPreferredScrollableViewportSize(javax.swing.text.JTextComponent t, Dimension ans)
  8. getRenderedLineOfChar(JTextComponent comp, int charIdx)
  9. getStoredBackground(JTextComponent comp)