本文整理汇总了Java中javax.swing.JFormattedTextField.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java JFormattedTextField.getValue方法的具体用法?Java JFormattedTextField.getValue怎么用?Java JFormattedTextField.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFormattedTextField
的用法示例。
在下文中一共展示了JFormattedTextField.getValue方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellEditorValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof Integer) {
return o;
} else if (o instanceof Number) {
return new Integer(((Number) o).intValue());
} else {
if (DEBUG) {
System.out.println("getCellEditorValue: o isn't a Number");
}
try {
return integerFormat.parseObject(o.toString());
} catch (ParseException exc) {
System.err.println("getCellEditorValue: can't parse o: " + o);
return null;
}
}
}
示例2: getCellEditorValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
@Override
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof Integer) {
return o;
} else if (o instanceof Number) {
return new Integer(((Number) o).intValue());
} else {
try {
return integerFormat.parseObject(o.toString());
} catch (ParseException ex) {
LOGGER.log(Level.FINE, "getCellEditorValue: can't parse {0}", o);
return null;
}
}
}
示例3: getCellEditorValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
@Override
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof Double) {
return o;
} else if (o instanceof Number) {
return new Double(((Number) o).doubleValue());
} else {
try {
return doubleFormat.parseObject(o.toString());
} catch (ParseException ex) {
LOGGER.log(Level.FINE, "getCellEditorValue: can't parse {0}", o);
return null;
}
}
}
示例4: getFormatter
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Returns either the default formatter, display formatter, editor
* formatter or null formatter based on the state of the
* JFormattedTextField.
*
* @param source JFormattedTextField requesting
* JFormattedTextField.AbstractFormatter
* @return JFormattedTextField.AbstractFormatter to handle
* formatting duties.
*/
public JFormattedTextField.AbstractFormatter getFormatter(
JFormattedTextField source) {
JFormattedTextField.AbstractFormatter format = null;
if (source == null) {
return null;
}
Object value = source.getValue();
if (value == null) {
format = getNullFormatter();
}
if (format == null) {
if (source.hasFocus()) {
format = getEditFormatter();
}
else {
format = getDisplayFormatter();
}
if (format == null) {
format = getDefaultFormatter();
}
}
return format;
}
示例5: stringToValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
@Override
public Object stringToValue (String string)
throws ParseException
{
try {
JFormattedTextField ftf = getFormattedTextField();
Object value = ftf.getValue();
if (value instanceof Integer) {
return Integer.valueOf(string, 16);
} else if (value instanceof Long) {
return Long.valueOf(string, 16);
} else {
throw new IllegalArgumentException(
"Illegal Number class for HexaFormatter " + value.getClass());
}
} catch (NumberFormatException ex) {
throw new ParseException(string, 0);
}
}
示例6: getFormatter
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public JFormattedTextField.AbstractFormatter getFormatter(
JFormattedTextField source) {
JFormattedTextField.AbstractFormatter format = null;
if (source == null) {
return null;
}
Object value = source.getValue();
if (value == null) {
format = getNullFormatter();
}
if (format == null) {
if (source.hasFocus()) {
format = getEditFormatter();
}
else {
format = getDisplayFormatter();
}
if (format == null) {
format = getDefaultFormatter();
}
}
return format;
}
示例7: getFormatter
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Returns the appropriate formatter based on the state of
* <code>tf</code>. If <code>tf<code> is null we return null, otherwise
* we return one of the following:
* 1. Returns <code>nullFormatter</code> if <code>tf.getValue()</code> is
* null and <code>nullFormatter</code> is not.
* 2. Returns <code>editFormatter</code> if <code>tf.hasFocus()</code> is
* true and <code>editFormatter</code> is not null.
* 3. Returns <code>displayFormatter</code> if <code>tf.hasFocus()</code> is
* false and <code>displayFormatter</code> is not null.
* 4. Otherwise returns <code>defaultFormatter</code>.
*/
public AbstractFormatter getFormatter(JFormattedTextField tf)
{
if (tf == null)
return null;
if (tf.getValue() == null && nullFormatter != null)
return nullFormatter;
if (tf.hasFocus() && editFormatter != null)
return editFormatter;
if (!tf.hasFocus() && displayFormatter != null)
return displayFormatter;
return defaultFormatter;
}
示例8: getTextFieldDoubleValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Reads the double value of a textfield and returns it
*
* @param tf
* textfield
* @return double value
*/
public static double getTextFieldDoubleValue(JFormattedTextField tf) {
Double d = 0.0;
int i = 0;
if (tf.getValue().getClass() == Double.class || tf.getValue().getClass() == double.class) {
d = (double) tf.getValue();
} else if (tf.getValue().getClass() == Integer.class || tf.getValue().getClass() == int.class) {
i = (Integer) tf.getValue();
d = (double) i;
} else if (tf.getValue().getClass() == long.class || tf.getValue().getClass() == Long.class) {
d = ((Long) tf.getValue()).doubleValue();
}
if (tf.getValue().getClass() == String.class) {
try {
String s = (String) tf.getValue();
d = Double.valueOf(s);
} catch (Exception e) {
}
}
return d;
}
示例9: getCellEditorValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
@Override
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof Date) {
return o;
} else {
try {
return dateFormat.parseObject(o.toString());
} catch (ParseException ex) {
LOGGER.log(Level.FINE, "getCellEditorValue: can't parse {0}", o);
return null;
}
}
}
示例10: getCellEditorValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
@Override
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof int[]) {
return o;
} else {
LOGGER.log(Level.FINE, "getCellEditorValue: can't parse {0}", o);
return null;
}
}
示例11: getCellEditorValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
@Override
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof double[]) {
return o;
} else {
LOGGER.log(Level.FINE, "getCellEditorValue: can't parse o{0}", o);
return null;
}
}
示例12: stringToValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Converts the passed in String into an instance of
* <code>getValueClass</code> by way of the constructor that takes a String
* argument. If <code>getValueClass</code> returns null, the Class of the
* current value in the <code>JFormattedTextField</code> will be used. If
* this is null, a String will be returned. If the constructor thows an
* exception, a <code>ParseException</code> will be thrown. If there is no
* single argument String constructor, <code>string</code> will be returned.
*
* @throws ParseException
* if there is an error in the conversion
* @param string
* String to convert
* @return Object representation of text
*/
public Object stringToValue(String string) throws ParseException {
Class<?> vc = getValueClass();
JFormattedTextField ftf = getFormattedTextField();
if (vc == null && ftf != null) {
Object value = ftf.getValue();
if (value != null) {
vc = value.getClass();
}
}
if (vc != null) {
Constructor cons;
try {
cons = vc.getConstructor(new Class[] { String.class });
} catch (NoSuchMethodException nsme) {
cons = null;
}
if (cons != null) {
try {
return cons.newInstance(new Object[] { string });
} catch (Throwable ex) {
throw new ParseException("Error creating instance", 0);
}
}
}
return string;
}