本文整理汇总了Java中javax.swing.JPasswordField.getFontMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java JPasswordField.getFontMetrics方法的具体用法?Java JPasswordField.getFontMetrics怎么用?Java JPasswordField.getFontMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JPasswordField
的用法示例。
在下文中一共展示了JPasswordField.getFontMetrics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modelToView
import javax.swing.JPasswordField; //导入方法依赖的package包/类
/**
* Provides a mapping from the document model coordinate space
* to the coordinate space of the view mapped to it.
*
* @param pos the position to convert >= 0
* @param a the allocated region to render into
* @return the bounding box of the given position
* @exception BadLocationException if the given position does not
* represent a valid location in the associated document
* @see View#modelToView
*/
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
Container c = getContainer();
if (c instanceof JPasswordField) {
JPasswordField f = (JPasswordField) c;
if (! f.echoCharIsSet()) {
return super.modelToView(pos, a, b);
}
char echoChar = f.getEchoChar();
FontMetrics m = f.getFontMetrics(f.getFont());
Rectangle alloc = adjustAllocation(a).getBounds();
int dx = (pos - getStartOffset()) * m.charWidth(echoChar);
alloc.x += dx;
alloc.width = 1;
return alloc;
}
return null;
}
示例2: getPreferredSpan
import javax.swing.JPasswordField; //导入方法依赖的package包/类
/**
* Determines the preferred span for this view along an
* axis.
*
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into >= 0.
* Typically the view is told to render into the span
* that is returned, although there is no guarantee.
* The parent may choose to resize or break the view.
*/
public float getPreferredSpan(int axis) {
switch (axis) {
case View.X_AXIS:
Container c = getContainer();
if (c instanceof JPasswordField) {
JPasswordField f = (JPasswordField) c;
if (f.echoCharIsSet()) {
char echoChar = f.getEchoChar();
FontMetrics m = f.getFontMetrics(f.getFont());
Document doc = getDocument();
return m.charWidth(echoChar) * getDocument().getLength();
}
}
}
return super.getPreferredSpan(axis);
}