本文整理匯總了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;
}