Java JTextComponent getPreferredScrollableViewportSize(javax.swing.text.JTextComponent t, Dimension ans)

Here you can find the source of getPreferredScrollableViewportSize(javax.swing.text.JTextComponent t, Dimension ans)

Description

Returns the preferred size of the viewport for component 't'.

License

Open Source License

Return

ans

Declaration

public static Dimension getPreferredScrollableViewportSize(javax.swing.text.JTextComponent t, Dimension ans) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2006-2013 AITIA International, Inc.
 * //from  ww w .j  a  va2s.  com
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

import java.awt.Dimension;

public class Main {
    /** Returns the preferred size of the viewport for component 't'. 'ans' is the
     *  initial preferred size.
     * @return ans
     */
    public static Dimension getPreferredScrollableViewportSize(javax.swing.text.JTextComponent t, Dimension ans) {
        java.awt.Container p = t.getParent();
        if (p instanceof javax.swing.JViewport) {
            p = p.getParent();
            if (p instanceof javax.swing.JScrollPane)
                shrink(ans, p.getMaximumSize());
        }
        return ans;
    }

    /** Shrinks 'a' to the size of 'b', if necessary. Returns true, if the shrinking
     *  has been necessary.
     */
    public static boolean shrink(Dimension a, Dimension b) {
        boolean ans = false;
        if (b != null) {
            if (b.width < a.width) {
                a.width = b.width;
                ans = true;
            }
            if (b.height < a.height) {
                a.height = b.height;
                ans = true;
            }
        }
        return ans;
    }
}

Related

  1. getAdjustedClickCount(JTextComponent comp, MouseEvent e)
  2. getCurrentTextBlock(JTextComponent textComponent)
  3. getNumberOfLines(final JTextComponent component)
  4. getParagraphElement(JTextComponent c, int offs)
  5. getPositionBelow(JTextComponent c, int offs, int x)
  6. getRenderedLineOfChar(JTextComponent comp, int charIdx)
  7. getStoredBackground(JTextComponent comp)
  8. getStoredBackground(JTextComponent comp)
  9. highlighterIsNext(JTextComponent textComponent, boolean forwards, Highlighter.Highlight highlight)