本文整理匯總了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;
}