本文整理汇总了Java中java.text.Format.formatToCharacterIterator方法的典型用法代码示例。如果您正苦于以下问题:Java Format.formatToCharacterIterator方法的具体用法?Java Format.formatToCharacterIterator怎么用?Java Format.formatToCharacterIterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.Format
的用法示例。
在下文中一共展示了Format.formatToCharacterIterator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatAndAppend
import java.text.Format; //导入方法依赖的package包/类
public void formatAndAppend(Format formatter, Object arg) {
if (attributes == null) {
append(formatter.format(arg));
} else {
AttributedCharacterIterator formattedArg = formatter.formatToCharacterIterator(arg);
int prevLength = length;
append(formattedArg);
// Copy all of the attributes from formattedArg to our attributes list.
formattedArg.first();
int start = formattedArg.getIndex(); // Should be 0 but might not be.
int limit = formattedArg.getEndIndex(); // == start + length - prevLength
int offset = prevLength - start; // Adjust attribute indexes for the result string.
while (start < limit) {
Map<Attribute, Object> map = formattedArg.getAttributes();
int runLimit = formattedArg.getRunLimit();
if (map.size() != 0) {
for (Map.Entry<Attribute, Object> entry : map.entrySet()) {
attributes.add(
new AttributeAndPosition(
entry.getKey(), entry.getValue(),
offset + start, offset + runLimit));
}
}
start = runLimit;
formattedArg.setIndex(start);
}
}
}
示例2: select
import java.text.Format; //导入方法依赖的package包/类
/**
* If the spinner's editor is a DateEditor, this selects the field
* associated with the value that is being incremented.
*/
private void select(JSpinner spinner)
{
JComponent editor = spinner.getEditor();
if( editor instanceof JSpinner.DateEditor )
{
JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
JFormattedTextField ftf = dateEditor.getTextField();
Format format = dateEditor.getFormat();
Object value = spinner.getValue();
if( format != null && value != null )
{
SpinnerDateModel model = dateEditor.getModel();
DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
if( field != null )
{
try
{
AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
if( !select(ftf, iterator, field) && field == DateFormat.Field.HOUR0 )
{
select(ftf, iterator, DateFormat.Field.HOUR1);
}
}
catch( IllegalArgumentException iae )
{
// ??
}
}
}
}
}