Example usage for javax.swing JLabel getVerticalTextPosition

List of usage examples for javax.swing JLabel getVerticalTextPosition

Introduction

In this page you can find the example usage for javax.swing JLabel getVerticalTextPosition.

Prototype

public int getVerticalTextPosition() 

Source Link

Document

Returns the vertical position of the label's text, relative to its image.

Usage

From source file:Main.java

public static String layoutLabel(JLabel label, Icon icon, Rectangle viewRect, Rectangle iconRect,
        Rectangle textRect) {/*from  w ww  . ja v  a 2s . com*/
    setViewBounds(label, viewRect);

    return layoutComponent(label, label.getText(), icon, label.getIconTextGap(), label.getVerticalAlignment(),
            label.getHorizontalAlignment(), label.getVerticalTextPosition(), label.getHorizontalTextPosition(),
            viewRect, iconRect, textRect);
}

From source file:Main.java

public static Rectangle getTextRectangle(JLabel label) {

    String text = label.getText();
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

    if ((icon == null) && (text == null)) {
        return null;
    }/*from  w ww.  j  a  v a  2s  .  co m*/

    Rectangle paintIconR = new Rectangle();
    Rectangle paintTextR = new Rectangle();
    Rectangle paintViewR = new Rectangle();
    Insets paintViewInsets = new Insets(0, 0, 0, 0);

    paintViewInsets = label.getInsets(paintViewInsets);
    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;
    paintViewR.width = label.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.height = label.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    Graphics g = label.getGraphics();
    if (g == null) {
        return null;
    }
    String clippedText = SwingUtilities.layoutCompoundLabel(label, g.getFontMetrics(), text, icon,
            label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(),
            label.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, label.getIconTextGap());

    return paintTextR;
}