当前位置: 首页>>代码示例>>Java>>正文


Java NumberFormatter类代码示例

本文整理汇总了Java中javax.swing.text.NumberFormatter的典型用法代码示例。如果您正苦于以下问题:Java NumberFormatter类的具体用法?Java NumberFormatter怎么用?Java NumberFormatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NumberFormatter类属于javax.swing.text包,在下文中一共展示了NumberFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initializeTextFields

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
private void initializeTextFields() {

		DecimalFormatSymbols symbols = new DecimalFormatSymbols();
		symbols.setDecimalSeparator('.');

		NumberFormat format = new DecimalFormat("0.00", symbols);
		format.setMaximumFractionDigits(2);

		NumberFormatter formatter = new NumberFormatter(format);
		formatter.setMinimum(0.0);
		formatter.setMaximum(10000000.0);
		formatter.setAllowsInvalid(false);

		this.txtPeso = new JFormattedTextField(formatter);
		this.txtPeso.setValue(0.0);

		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.gridwidth = 10;
		gbc_textField.insets = new Insets(0, 0, 5, 0);
		gbc_textField.fill = GridBagConstraints.BOTH;
		gbc_textField.gridx = 2;
		gbc_textField.gridy = 10;
		this.panelSecond.add(this.txtPeso, gbc_textField);
		this.txtPeso.setColumns(10);

	}
 
开发者ID:cjlcarvalho,项目名称:LogisticApp,代码行数:27,代码来源:MenuContratacaoTransporteFrame.java

示例2: createNumberFormatterDisplay

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
/**
 * Creates a {@link NumberFormatter} for display-mode from a given {@link NumberFormat}.
 *
 * @param format for the formatter
 * @return created {@link NumberFormatter}
 * @see NumberFormat
 * @see NumberFormatter
 * @since 0.0.1
 */
public static NumberFormatter createNumberFormatterDisplay(final NumberFormat format) {
	if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(format));
	if (null == format) {
		throw new RuntimeExceptionIsNull("format"); //$NON-NLS-1$
	}

	final NumberFormatter result = new NumberFormatter(format) {
		private static final long serialVersionUID = -8279122736069976223L;

		{
			setCommitsOnValidEdit(true);
		}
	};

	if (log.isDebugEnabled()) log.debug(HelperLog.methodExit(result));
	return result;
}
 
开发者ID:slaubenberger,项目名称:wichtel,代码行数:27,代码来源:FormatFactory.java

示例3: WettDialog

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
/**
    * Creates a new WettDialog and displays the given array of snails.
    * @param parent The Form opening this dialog
    * @param schneggen The array of snails to display
    * @param wettbueroFactor The factor the Wettbuero uses.
    */
   public WettDialog(Frame parent, ArrayList<Rennschnecke> schneggen, double wettbueroFactor) {
       super(parent, true);
       initComponents();
       NumberFormat format = NumberFormat.getCurrencyInstance();
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
       NumberFormatter nf = new NumberFormatter(format);
       nf.setMinimum(0.02);
// The maximum bet value is, well, pretty high.
       nf.setMaximum(Double.MAX_VALUE / wettbueroFactor);
       nf.setAllowsInvalid(false);
       nf.setCommitsOnValidEdit(true);
       nf.setOverwriteMode(false);
       einsatzInput.setFormatterFactory(
               new DefaultFormatterFactory(nf)
       );
       result = null;
       snailList.setModel(new DefaultListModel<>());
       snailList.setListData(schneggen.toArray(new Rennschnecke[schneggen.size()]));
   }
 
开发者ID:Follpvosten,项目名称:schneckenrennen,代码行数:27,代码来源:WettDialog.java

示例4: NumberPropertyEditor

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
public NumberPropertyEditor(Class type) {
  if (!Number.class.isAssignableFrom(type)) {
    throw new IllegalArgumentException("type must be a subclass of Number");
  }

  editor = new JFormattedTextField();
  this.type = type;
  ((JFormattedTextField)editor).setValue(getDefaultValue());
  ((JFormattedTextField)editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);

  // use a custom formatter to have numbers with up to 64 decimals
  NumberFormat format = NumberConverters.getDefaultFormat();

  ((JFormattedTextField) editor).setFormatterFactory(
      new DefaultFormatterFactory(new NumberFormatter(format))
  );
}
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:18,代码来源:NumberPropertyEditor.java

示例5: IntegerEditor

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
/**
 * Construct a <code>JSpinner</code> editor that supports displaying and
 * editing the value of a <code>SpinnerIntModel</code> with a
 * <code>JFormattedTextField</code>. <code>This</code>
 * <code>IntegerEditor</code> becomes both a <code>ChangeListener</code>
 * on the spinner and a <code>PropertyChangeListener</code> on the new
 * <code>JFormattedTextField</code>.
 *
 * @param spinner the spinner whose model <code>this</code> editor will
 *            monitor
 * @param format the <code>NumberFormat</code> object that's used to
 *            display and parse the value of the text field.
 * @exception IllegalArgumentException if the spinners model is not an
 *                instance of <code>SpinnerIntModel</code>
 *
 * @see #getTextField
 * @see SpinnerIntModel
 * @see java.text.DecimalFormat
 */
private IntegerEditor(JSpinner spinner, NumberFormat format) {
	super(spinner);
	if (!(spinner.getModel() instanceof SpinnerIntModel)) {
		throw new IllegalArgumentException("model not a SpinnerIntModel");
	}

	format.setGroupingUsed(false);
	format.setMaximumFractionDigits(0);
	SpinnerIntModel model = (SpinnerIntModel) spinner.getModel();
	NumberFormatter formatter = new IntegerEditorFormatter(model, format);
	DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
	JFormattedTextField ftf = getTextField();
	ftf.setEditable(true);
	ftf.setFormatterFactory(factory);
	ftf.setHorizontalAlignment(JTextField.RIGHT);

	try {
		String minString = formatter.valueToString(model.getMinimum());
		String maxString = formatter.valueToString(model.getMaximum());
		// Trying to approximate the width difference between "m" and "0" by multiplying with 0.7
		ftf.setColumns((int) Math.round(0.7 * Math.max(maxString.length(), minString.length())));
	} catch (ParseException e) {
		// Nothing to do, the component width will simply be the default
	}
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:45,代码来源:CustomJSpinner.java

示例6: formatNumber

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
public static String formatNumber(Number num, int digits) {

        String s = "0.";
        for (int i = 0; i < digits; i++) {
            s += "0";
        }
        DecimalFormat df = new DecimalFormat(s);

        NumberFormatter nf = new NumberFormatter(df);

        String out = "Illegal Format";
        try {
            out = nf.valueToString(num);
        } catch (ParseException e) {
        }
        return out;
    }
 
开发者ID:nolanlab,项目名称:vortex,代码行数:18,代码来源:Formatter.java

示例7: getValorTitulo

import javax.swing.text.NumberFormatter; //导入依赖的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

示例8: JNumberField

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
public JNumberField(double defaultNumber, double minValue, double maxValue, double increment)
{
    super(new SpinnerNumberModel(defaultNumber, minValue, maxValue, increment));

    final NumberEditor editor = (NumberEditor) this.getEditor();
    editor.getFormat().setMinimumFractionDigits(2);
    editor.getFormat().setMaximumFractionDigits(6);

    final JFormattedTextField spinnerTextEditor = editor.getTextField();
    spinnerTextEditor.setColumns(6);
    spinnerTextEditor.setHorizontalAlignment(JTextField.CENTER);

    final NumberFormatter numberFormatter = new NumberFormatter(editor.getFormat());
    numberFormatter.setValueClass(Double.class);
    numberFormatter.setMinimum(0d);
    numberFormatter.setMaximum(Double.MAX_VALUE);
    numberFormatter.setAllowsInvalid(false);

    spinnerTextEditor.setFormatterFactory(new JFormattedTextField(numberFormatter).getFormatterFactory());
}
 
开发者ID:girtel,项目名称:Net2Plan,代码行数:21,代码来源:JNumberField.java

示例9: getImageSizePanel

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
private JPanel getImageSizePanel() {
	JPanel imageSizePanel = new JPanel();
	imageSizePanel.setLayout(new GridLayout(1, 4));
	
    NumberFormat format = NumberFormat.getInstance();
    format.setGroupingUsed(false);
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.setMinimum(0);
    formatter.setMaximum(Integer.MAX_VALUE);
    formatter.setCommitsOnValidEdit(true);
    widthTF = new JFormattedTextField(formatter);
    widthTF.setValue(1200);
    addFocusListener(widthTF);
    heightTF = new JFormattedTextField(formatter);
    heightTF.setValue(1000);
    addFocusListener(heightTF);
    
    imageSizePanel.add(new JLabel(" Width:"));
    imageSizePanel.add(widthTF);
    imageSizePanel.add(new JLabel(" Height:"));
    imageSizePanel.add(heightTF);
    
	return imageSizePanel;
}
 
开发者ID:sing-group,项目名称:la-images,代码行数:26,代码来源:ExportAllAsPngDialog.java

示例10: getImageSizePanel

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
private JPanel getImageSizePanel() {
	JPanel imageSizePanel = new JPanel();
	imageSizePanel.setLayout(new GridLayout(1, 4));
	
    NumberFormat format = NumberFormat.getInstance();
    format.setGroupingUsed(false);
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.setMinimum(0);
    formatter.setMaximum(Integer.MAX_VALUE);
    formatter.setCommitsOnValidEdit(true);
    widthTF = new JFormattedTextField(formatter);
    widthTF.setValue(1200);
    widthTF.addFocusListener(FOCUS_LISTENER);
    heightTF = new JFormattedTextField(formatter);
    heightTF.setValue(1000);
    heightTF.addFocusListener(FOCUS_LISTENER);
    
    imageSizePanel.add(new JLabel(" Width:"));
    imageSizePanel.add(widthTF);
    imageSizePanel.add(new JLabel(" Height:"));
    imageSizePanel.add(heightTF);
    
	return imageSizePanel;
}
 
开发者ID:sing-group,项目名称:la-images,代码行数:26,代码来源:ExportAsPngDialog.java

示例11: getIntegerTextField

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
public JFormattedTextField getIntegerTextField(Integer min, Integer max, Integer value) {
    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.setMinimum(min);
    formatter.setMaximum(max);
    formatter.setAllowsInvalid(true);
    formatter.setCommitsOnValidEdit(false);

    JFormattedTextField field = new JFormattedTextField(formatter);
    field.setValue(value);
    field.setFont(REGULAR_FONT.deriveFont(scale * 18));
    field.setFocusLostBehavior(JFormattedTextField.PERSIST);
    field.setForeground(AppThemeColor.TEXT_DEFAULT);
    field.setCaretColor(AppThemeColor.TEXT_DEFAULT);
    field.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(AppThemeColor.BORDER, 1),
            BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 3)
    ));
    field.setBackground(AppThemeColor.HEADER);
    return field;
}
 
开发者ID:Exslims,项目名称:MercuryTrade,代码行数:23,代码来源:ComponentsFactory.java

示例12: JIntegerTextField

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
public JIntegerTextField() {
    super();
    DecimalFormat df = new DecimalFormat("####");
    nf = new NumberFormatter(df) {
        @Override
        public String valueToString(Object iv) throws ParseException {
            if ((iv == null) || (((Number) iv).intValue() == -1)) {
                return "";
            }
            return super.valueToString(iv);
        }

        @Override
        public Object stringToValue(String text) throws ParseException {
            if ("".equals(text)) {
                return null;
            }
            return super.stringToValue(text);
        }
    };
    nf.setValueClass(Integer.class);
    this.setFormatter(nf);
}
 
开发者ID:vrsl,项目名称:MDD-JPA,代码行数:24,代码来源:JIntegerTextField.java

示例13: setupIntegerFieldTrackingValue

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
/**
 * Sets integer number format to JFormattedTextField instance,
 * sets value of JFormattedTextField instance to object's field value,
 * synchronizes object's field value with the value of JFormattedTextField instance.
 *
 * @param textField  JFormattedTextField instance
 * @param owner      an object whose field is synchronized with {@code textField}
 * @param property   object's field name for synchronization
 */
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField,
                                                  final InspectionProfileEntry owner,
                                                  final String property) {
    NumberFormat formatter = NumberFormat.getIntegerInstance();
    formatter.setParseIntegerOnly(true);
    textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
    textField.setValue(getPropertyValue(owner, property));
    final Document document = textField.getDocument();
    document.addDocumentListener(new DocumentAdapter() {
        @Override
        public void textChanged(DocumentEvent e) {
            try {
                textField.commitEdit();
                setPropertyValue(owner, property,
                        ((Number) textField.getValue()).intValue());
            } catch (ParseException e1) {
                // No luck this time
            }
        }
    });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:SingleIntegerFieldOptionsPanel.java

示例14: PropertyDoubleEditor

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
/**
 * Constructor.
 * @param property The property which should be edited.
 * @param configuration The configuration which should be edited.
 * @param client YouScope client
 * @param server YouScope server.
 * @throws GenericException
 */
public PropertyDoubleEditor(Property property, Configuration configuration, YouScopeClient client, YouScopeServer server) throws GenericException
{
	super(property, configuration, client, server, Double.class, double.class);
	field = new JFormattedTextField(new NumberFormatter(getDoubleFormat()));
	field.setValue(getValue(Double.class));
	addLabel();
	add(field);
	field.addActionListener(new ActionListener() 
	{
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			try 
			{
				commitEdits();
				notifyPropertyValueChanged();
			} 
			catch (GenericException e1) 
			{
				sendErrorMessage("Could not set value of property " + getProperty().getName() + ".", e1);
			}
		}
	});
}
 
开发者ID:langmo,项目名称:youscope,代码行数:33,代码来源:PropertyDoubleEditor.java

示例15: NumberPropertyEditor

import javax.swing.text.NumberFormatter; //导入依赖的package包/类
public NumberPropertyEditor(Class<?> type) {
    if (!Number.class.isAssignableFrom(type)) {
        throw new IllegalArgumentException("type must be a subclass of Number");
    }

    editor = new JFormattedTextField();
    this.type = type;
    ((JFormattedTextField) editor).setValue(getDefaultValue());
    ((JFormattedTextField) editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);

    // use a custom formatter to have numbers with up to 64 decimals
    NumberFormat format = NumberConverters.DEFAULT_FORMAT;

    ((JFormattedTextField) editor).setFormatterFactory(
            new DefaultFormatterFactory(new NumberFormatter(format))
    );
}
 
开发者ID:ZenHarbinger,项目名称:l2fprod-properties-editor,代码行数:18,代码来源:NumberPropertyEditor.java


注:本文中的javax.swing.text.NumberFormatter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。