本文整理汇总了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;
}