本文整理汇总了Java中java.text.DateFormat.Field方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.Field方法的具体用法?Java DateFormat.Field怎么用?Java DateFormat.Field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DateFormat
的用法示例。
在下文中一共展示了DateFormat.Field方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: select
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* Selects the passed in field, returning true if it is found, false
* otherwise.
*/
private boolean select(JFormattedTextField ftf, AttributedCharacterIterator iterator, DateFormat.Field field)
{
int max = ftf.getDocument().getLength();
iterator.first();
do
{
Map<Attribute, Object> attrs = iterator.getAttributes();
if( attrs != null && attrs.containsKey(field) )
{
int start = iterator.getRunStart(field);
int end = iterator.getRunLimit(field);
if( start != -1 && end != -1 && start <= max && end <= max )
{
ftf.select(start, end);
}
return true;
}
}
while( iterator.next() != CharacterIterator.DONE );
return false;
}
示例2: getCalendarField
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* Returns the calendarField under the start of the selection, or -1 if
* there is no valid calendar field under the selection (or the spinner
* isn't editing dates.
*/
private int getCalendarField(JSpinner spinner)
{
JComponent editor = spinner.getEditor();
if( editor instanceof JSpinner.DateEditor )
{
JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
JFormattedTextField ftf = dateEditor.getTextField();
int start = ftf.getSelectionStart();
JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
if( formatter instanceof InternationalFormatter )
{
Format.Field[] fields = ((InternationalFormatter) formatter).getFields(start);
for( int counter = 0; counter < fields.length; counter++ )
{
if( fields[counter] instanceof DateFormat.Field )
{
int calendarField;
if( fields[counter] == DateFormat.Field.HOUR1 )
{
calendarField = Calendar.HOUR;
}
else
{
calendarField = ((DateFormat.Field) fields[counter]).getCalendarField();
}
if( calendarField != -1 )
{
return calendarField;
}
}
}
}
}
return -1;
}