當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultFormatter類代碼示例

本文整理匯總了Java中javax.swing.text.DefaultFormatter的典型用法代碼示例。如果您正苦於以下問題:Java DefaultFormatter類的具體用法?Java DefaultFormatter怎麽用?Java DefaultFormatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultFormatter類屬於javax.swing.text包,在下文中一共展示了DefaultFormatter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getValorTitulo

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
public String getValorTitulo() {

		String zeros = "0000000000";
		DefaultFormatter formatter = new NumberFormatter(new DecimalFormat("#,##0.00"));

		String valor = "";

		try {
			valor = formatter.valueToString(getValorTituloBigDecimal());
		}
		catch (Exception ex) {
		}

		valor = valor.replace(",", "").replace(".", "");
		String valorTitulo = zeros.substring(0, zeros.length() - valor.length()) + valor;

		return valorTitulo;
	}
 
開發者ID:cams7,項目名稱:erp,代碼行數:19,代碼來源:Bradesco.java

示例2: setCommitOnValidEdit

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
@Override
public void setCommitOnValidEdit(final boolean commit)
{
	if (textComponent instanceof JFormattedTextField)
	{
		final JFormattedTextField formattedTextField = (JFormattedTextField)textComponent;
		final AbstractFormatter formatter = formattedTextField.getFormatter();
		if (formatter instanceof DefaultFormatter)
		{
			final DefaultFormatter defaultFormatter = (DefaultFormatter)formatter;
			defaultFormatter.setCommitsOnValidEdit(commit);
			return;
		}
	}
	else if (textComponent instanceof JTextArea)
	{
		// ignore it for now
	}
	else
	{
		throw new UnsupportedOperationException("setCommitOnValidValue not supported for " + this);
	}
}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:24,代碼來源:SwingTerminalTextField.java

示例3: NumberEditor

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
public NumberEditor(String fieldName, Object obj, Field field, int index, Class<?> type, SWFType swfType) {
    setSize(100, getSize().height);
    setMaximumSize(getSize());
    this.obj = obj;
    this.field = field;
    this.index = index;
    this.type = type;
    this.swfType = swfType;
    this.fieldName = fieldName;

    reset();
    JFormattedTextField jtf = ((JSpinner.NumberEditor) getEditor()).getTextField();
    DefaultFormatter formatter = (DefaultFormatter) jtf.getFormatter();
    formatter.setCommitsOnValidEdit(true);

}
 
開發者ID:jindrapetrik,項目名稱:jpexs-decompiler,代碼行數:17,代碼來源:NumberEditor.java

示例4: setSpinner

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
private void setSpinner() {
	spinnerAmount.setModel(new SpinnerNumberModel(new Float(0), new Float(0), new Float(Float.MAX_VALUE), new Float(1f)));
	spinnerAmount.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
	JTextField tf = ((JSpinner.DefaultEditor) spinnerAmount.getEditor()).getTextField();
	tf.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
	tf.setHorizontalAlignment(SwingConstants.CENTER);
	JFormattedTextField field = (JFormattedTextField) spinnerAmount.getEditor().getComponent(0);
	DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
    formatter.setCommitsOnValidEdit(true);
	JSpinner.NumberEditor editor = (JSpinner.NumberEditor)spinnerAmount.getEditor();  
       DecimalFormat format = editor.getFormat();  
       format.setMinimumFractionDigits(8);  
       
	//tf.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
	//tf.setHorizontalAlignment(SwingConstants.CENTER);
       //DecimalFormat format = editor.getFormat();  
       //format.setMinimumFractionDigits(8);  
}
 
開發者ID:pavel4n,項目名稱:wowdoge.org,代碼行數:19,代碼來源:DialogRequestPayment.java

示例5: NumberField

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
/** Creates a new instance of NumberField */
public NumberField() {
    
    // define a custom input verifier
    this.setInputVerifier(new NumberVerifier());
    
    // create a formatter for displaying and editing
    DefaultFormatter formatter = new DefaultFormatter();
    
    // allow the user to completely delete all text
    formatter.setAllowsInvalid(true);
    
    // typing should insert new characters and not overwrite old ones
    formatter.setOverwriteMode(false);
    
    // commit on edit, otherwise a property change event is generated
    // when the field loses the focus and the value changed since it gained
    // the focus.
    formatter.setCommitsOnValidEdit(true);
    
    // getValue should return a Double object
    formatter.setValueClass(java.lang.Double.class);
    
    // the kind of formatter getFormatter should return
    this.setFormatterFactory(new DefaultFormatterFactory(formatter));
    
    // default value is 0
    this.setValue(new Double(0));
}
 
開發者ID:berniejenny,項目名稱:MapAnalyst,代碼行數:30,代碼來源:NumberField.java

示例6: testDefaultFormatter

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
private static void testDefaultFormatter(DefaultFormatter formatter ) {
    try {
        System.out.println("formatter: " + formatter.getClass());
        formatter.setValueClass(UserValueClass.class);
        UserValueClass userValue = (UserValueClass) formatter.stringToValue("test");

        if (!userValue.str.equals("test")) {
            throw new RuntimeException("String value is wrong!");
        }
    } catch (ParseException ex) {
        throw new RuntimeException(ex);
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:TestDefaultFormatter.java

示例7: createField

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
private EditorField createField(String text, String prototype, String tooltip) {
    DefaultFormatter formatter = new DefaultFormatter();
    formatter.setOverwriteMode(false);
    EditorField field = new EditorField(new DefaultFormatterFactory(formatter), this, SwingConstants.LEFT, text, prototype, tooltip);
    field.setEnabled(mIsEditable);
    add(field);
    return field;
}
 
開發者ID:richardwilkes,項目名稱:gcs,代碼行數:9,代碼來源:AdvantageEditor.java

示例8: createTextField

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
/**
 * Creates a new text field.
 *
 * @param parent The parent.
 * @param title The title of the field.
 * @param value The initial value.
 * @return The newly created field.
 */
protected EditorField createTextField(Container parent, String title, Object value) {
    DefaultFormatter formatter = new DefaultFormatter();
    formatter.setOverwriteMode(false);
    EditorField field = new EditorField(new DefaultFormatterFactory(formatter), this, SwingConstants.LEFT, value, null);
    parent.add(new LinkedLabel(title, field));
    parent.add(field);
    return field;
}
 
開發者ID:richardwilkes,項目名稱:gcs,代碼行數:17,代碼來源:WeaponEditor.java

示例9: addStringCompareField

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
/**
 * @param compare The current string compare object.
 * @return The field that allows a string comparison to be changed.
 */
protected EditorField addStringCompareField(StringCriteria compare) {
    DefaultFormatter formatter = new DefaultFormatter();
    formatter.setOverwriteMode(false);
    EditorField field = new EditorField(new DefaultFormatterFactory(formatter), this, SwingConstants.LEFT, compare.getQualifier(), null);
    field.putClientProperty(StringCriteria.class, compare);
    add(field);
    return field;
}
 
開發者ID:richardwilkes,項目名稱:gcs,代碼行數:13,代碼來源:EditorPanel.java

示例10: IntegerSpinner

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
/**
 * Instantiates a new value spinner.
 */
public IntegerSpinner(int min, int max, int stepSize) {
    SpinnerNumberModel model = new SpinnerNumberModel(min, min, max, stepSize);
    setModel(model);

    JComponent comp = getEditor();
    final JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
    DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
    formatter.setCommitsOnValidEdit(true);
    addChangeListener(new ChangeListener() {
        private double oldValue = Double.MAX_VALUE;

        @Override
        public void stateChanged(ChangeEvent e) {

            Double doubleValue = IntegerSpinner.this.getDoubleValue();

            if (doubleValue != oldValue) {
                double oldValueCopy = oldValue;

                oldValue = doubleValue;
                if (minIsZero) {
                    if (doubleValue < 0.0) {
                        doubleValue = 0.0;
                        field.setValue(doubleValue);
                    }
                }

                notifyListeners(oldValueCopy, doubleValue);
            }
        }
    });
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:36,代碼來源:IntegerSpinner.java

示例11: createUI

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
/**
 * Creates the ui.
 *
 * @param initialValue the initial value
 * @param min the min
 * @param max the max
 * @param stepSize the step size
 * @param noOfDecimalPlaces the no of decimal places
 */
private void createUI(Double initialValue, Double min, Double max, Double stepSize,
        double noOfDecimalPlaces) {
    SpinnerNumberModel model = new SpinnerNumberModel(initialValue, min, max, stepSize);
    setModel(model);

    JSpinner.NumberEditor editor = (JSpinner.NumberEditor) getEditor();
    DecimalFormat format = editor.getFormat();
    format.setMinimumFractionDigits(3);

    final JFormattedTextField field = (JFormattedTextField) editor.getTextField();
    DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
    formatter.setCommitsOnValidEdit(true);
    addChangeListener(new ChangeListener() {
        private double oldValue = Double.MAX_VALUE;

        @Override
        public void stateChanged(ChangeEvent e) {

            Double doubleValue = DecimalSpinner.this.getDoubleValue();

            if (doubleValue != oldValue) {
                double oldValueCopy = oldValue;

                oldValue = doubleValue;
                if (minIsZero) {
                    if (doubleValue < 0.0) {
                        doubleValue = 0.0;
                        field.setValue(doubleValue);
                    }
                }

                notifyListeners(oldValueCopy, doubleValue);
            }
        }
    });
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:46,代碼來源:DecimalSpinner.java

示例12: getDefaultFormatterFactory

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
/**
 * Returns an AbstractFormatterFactory suitable for the passed in Object
 * type.
 */
private AbstractFormatterFactory getDefaultFormatterFactory(Object type) {
	if (type instanceof DateFormat) {
		return new DefaultFormatterFactory(new DateFormatter(
				(DateFormat) type));
	}
	if (type instanceof NumberFormat) {
		return new DefaultFormatterFactory(new NumberFormatter(
				(NumberFormat) type));
	}
	if (type instanceof Format) {
		return new DefaultFormatterFactory(new InternationalFormatter(
				(Format) type));
	}
	if (type instanceof Date) {
		return new DefaultFormatterFactory(new DateFormatter());
	}
	if (type instanceof Number) {
		AbstractFormatter displayFormatter = new NumberFormatter();
		((NumberFormatter) displayFormatter).setValueClass(type.getClass());
		AbstractFormatter editFormatter = new NumberFormatter(
				new DecimalFormat("#.#"));
		((NumberFormatter) editFormatter).setValueClass(type.getClass());

		return new DefaultFormatterFactory(displayFormatter,
				displayFormatter, editFormatter);
	}
	return new DefaultFormatterFactory(new DefaultFormatter());
}
 
開發者ID:javalovercn,項目名稱:j2se_for_android,代碼行數:33,代碼來源:JFormattedTextField.java

示例13: createFactory

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
private AbstractFormatterFactory createFactory(final Object value) {
    DefaultFormatterFactory factory = new DefaultFormatterFactory();
    if (value instanceof Number) {
        factory.setDefaultFormatter(new NumberFormatter());
    } else if (value instanceof Date) {
        factory.setDefaultFormatter(new DateFormatter());
    } else {
        factory.setDefaultFormatter(new DefaultFormatter());
    }
    return factory;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:12,代碼來源:JFormattedTextField.java

示例14: testJFormattedTextFieldObject

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
public void testJFormattedTextFieldObject() {
    Object value = Color.RED;
    JFormattedTextField tf1 = new JFormattedTextField(value);
    assertEquals(value, tf1.getValue());
    assertEquals(JFormattedTextField.COMMIT_OR_REVERT, tf1.getFocusLostBehavior());
    assertTrue(tf1.getFormatter() instanceof DefaultFormatter);
    assertTrue(tf1.getFormatterFactory() instanceof DefaultFormatterFactory);
    DefaultFormatterFactory factory = (DefaultFormatterFactory) tf1.getFormatterFactory();
    assertTrue(factory.getDefaultFormatter() instanceof DefaultFormatter);
    assertNull(factory.getEditFormatter());
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getNullFormatter());
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:14,代碼來源:JFormattedTextFieldTest.java

示例15: customInit

import javax.swing.text.DefaultFormatter; //導入依賴的package包/類
private void customInit() {
    setFocusLostBehavior(COMMIT);
    if (getFormatter() instanceof DefaultFormatter) {
        final DefaultFormatter d = (DefaultFormatter)getFormatter();
        AbstractAction toggleOverwrite = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                d.setOverwriteMode(!(d.getOverwriteMode()));
            }
        };
        getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0), TOGGLE_OVERWRITE_MODE_ACTION);
        getActionMap().put(TOGGLE_OVERWRITE_MODE_ACTION, toggleOverwrite);
    }
}
 
開發者ID:shevek,項目名稱:spring-rich-client,代碼行數:14,代碼來源:PatchedJFormattedTextField.java


注:本文中的javax.swing.text.DefaultFormatter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。