Java JTextComponent getNumberOfLines(final JTextComponent component)

Here you can find the source of getNumberOfLines(final JTextComponent component)

Description

get Number Of Lines

License

Open Source License

Declaration

public static int getNumberOfLines(final JTextComponent component) 

Method Source Code


//package com.java2s;
/*/*from   w  w  w.ja  v a2  s  . com*/
Copyright 2015 Google Inc. All Rights Reserved.
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import javax.swing.text.Element;
import javax.swing.text.JTextComponent;

public class Main {
    public static int getNumberOfLines(final JTextComponent component) {
        final Element root = component.getDocument().getDefaultRootElement();

        return root.getElementCount();
    }
}

Related

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