當前位置: 首頁>>代碼示例>>Java>>正文


Java JLabel.getBaseline方法代碼示例

本文整理匯總了Java中javax.swing.JLabel.getBaseline方法的典型用法代碼示例。如果您正苦於以下問題:Java JLabel.getBaseline方法的具體用法?Java JLabel.getBaseline怎麽用?Java JLabel.getBaseline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JLabel的用法示例。


在下文中一共展示了JLabel.getBaseline方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBaseline

import javax.swing.JLabel; //導入方法依賴的package包/類
/**
 * Returns the baseline.
 *
 * @throws NullPointerException {@inheritDoc}
 * @throws IllegalArgumentException {@inheritDoc}
 * @see javax.swing.JComponent#getBaseline(int, int)
 * @since 1.6
 */
public int getBaseline(Component c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Must supply non-null component");
    }
    if (width < 0) {
        throw new IllegalArgumentException("Width must be >= 0");
    }
    if (height < 0) {
        throw new IllegalArgumentException("Height must be >= 0");
    }
    Border border = getBorder();
    String title = getTitle();
    if ((title != null) && !title.isEmpty()) {
        int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING;
        JLabel label = getLabel(c);
        Dimension size = label.getPreferredSize();
        Insets insets = getBorderInsets(border, c, new Insets(0, 0, 0, 0));

        int baseline = label.getBaseline(size.width, size.height);
        switch (getPosition()) {
            case ABOVE_TOP:
                return baseline;
            case TOP:
                insets.top = edge + (insets.top - size.height) / 2;
                return (insets.top < edge)
                        ? baseline
                        : baseline + insets.top;
            case BELOW_TOP:
                return baseline + insets.top + edge;
            case ABOVE_BOTTOM:
                return baseline + height - size.height - insets.bottom - edge;
            case BOTTOM:
                insets.bottom = edge + (insets.bottom - size.height) / 2;
                return (insets.bottom < edge)
                        ? baseline + height - size.height
                        : baseline + height - size.height + insets.bottom;
            case BELOW_BOTTOM:
                return baseline + height - size.height;
        }
    }
    return -1;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:51,代碼來源:TitledBorder.java


注:本文中的javax.swing.JLabel.getBaseline方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。