本文整理匯總了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 )
{
// ??
}
}
}
}
}