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


Java NumberFormatter.setValueClass方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: editStackSize

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
public static Dimension editStackSize(Dimension currentSize, Component parent) {
    StackSizeEditor dialog = new StackSizeEditor();
    dialog.stackDimension = currentSize;

    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.setMinimum(0);
    formatter.setMaximum(Integer.MAX_VALUE);
    formatter.setAllowsInvalid(false);
    formatter.setCommitsOnValidEdit(true);

    dialog.newHeight.setFormatterFactory(new DefaultFormatterFactory(formatter));
    dialog.newWidth.setFormatterFactory(new DefaultFormatterFactory(formatter));

    dialog.currentStackSize.setText("Stack is " + currentSize.width + "px by " + currentSize.height + "px");
    dialog.newWidth.setText(String.valueOf(currentSize.width));
    dialog.newHeight.setText(String.valueOf(currentSize.height));

    dialog.pack();
    dialog.setLocationRelativeTo(parent);
    dialog.setVisible(true);

    return dialog.stackDimension;
}
 
开发者ID:defano,项目名称:hypertalk-java,代码行数:26,代码来源:StackSizeEditor.java

示例7: createIntegerField

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
 * @param min minimum value
 * @param max maximum value
 * @return text field for editing integers
 */
public static JFormattedTextField createIntegerField(final int min,
                                                     final int max) {

  final NumberFormatter def = new NumberFormatter();
  def.setValueClass(Integer.class);
  final NumberFormatter disp = new NumberFormatter((new DecimalFormat("#,###,##0")));
  disp.setValueClass(Integer.class);
  final NumberFormatter ed = new NumberFormatter((new DecimalFormat("#,###,##0")));
  ed.setValueClass(Integer.class);
  final DefaultFormatterFactory factory = new DefaultFormatterFactory(def, disp, ed);

  final JFormattedTextField field = new JFormattedTextField(factory);
  field.setValue(Integer.valueOf(min));
  field.setInputVerifier(new IntegerVerifier(min, max));
  return field;
}
 
开发者ID:jpschewe,项目名称:fll-sw,代码行数:22,代码来源:FormatterUtils.java

示例8: createUIComponents

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private void createUIComponents() {
    NumberFormat format = NumberFormat.getInstance();
    format.setGroupingUsed(false);
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.setMaximum(65535);
    formatter.setAllowsInvalid(false);
    formatter.setCommitsOnValidEdit(true);
    portTextField = new JFormattedTextField(formatter);
    jvmPortTextField = new JFormattedTextField(formatter);

    appsMap = new JBTable(new ModulesTableModel());

}
 
开发者ID:machaval,项目名称:mule-intellij-plugins,代码行数:15,代码来源:MuleRemoteDebuggerConfPanel.java

示例9: buildNumberTextField

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private static JTextField buildNumberTextField()
{
	// TODO: Verifying user input
	NumberFormatter formatter = new NumberFormatter( new DecimalFormat( "0" ) );
	formatter.setValueClass( Integer.class );
	formatter.setMinimum( Integer.MIN_VALUE );
	formatter.setMaximum( Integer.MAX_VALUE );
	formatter.setAllowsInvalid( false );

	JFormattedTextField result = new JFormattedTextField();
	result.setHorizontalAlignment( SwingConstants.RIGHT );
	result.setColumns( 10 );

	return result;
}
 
开发者ID:kartoFlane,项目名称:hiervis,代码行数:16,代码来源:HKOptionsPanel.java

示例10: createFormatter

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
private static NumberFormatter createFormatter(int min, int max) {
   NumberFormatter nf = new NumberFormatter(NumberFormat.getInstance());
   nf.setValueClass(Integer.class);
   nf.setMinimum(min);
   nf.setMaximum(max);
   return nf;
}
 
开发者ID:pushkarkp,项目名称:twidlit,代码行数:8,代码来源:IntegerTextField.java

示例11: createUIComponents

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
 * Custom initialization code from form
 */
private void createUIComponents() {
  NumberFormat numberFormat = NumberFormat.getInstance();
  NumberFormatter formatter = new NumberFormatter(numberFormat);

  formatter.setValueClass(Integer.class);
  formatter.setMaximum(1000);
  formatter.setMinimum(1);
  formatter.setCommitsOnValidEdit(true);
  formatter.setOverwriteMode(true);

  pasteToFetch = new JFormattedTextField(formatter);
  pasteToFetch.setValue(50);
}
 
开发者ID:kennedyoliveira,项目名称:ultimate-pastebin-intellij-plugin,代码行数:17,代码来源:PasteBinConfigurationForm.java

示例12: testFloatStringToValuePositive

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
 * Issue #1528-swingx: numbereditor doesn't allow negative values.
 * 
 * Sanity: positive okay
 * @throws ParseException 
 */
@Test
public void testFloatStringToValuePositive() throws ParseException {
    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new StrictNumberFormatter(format);
    formatter.setValueClass(Float.class);
    float value = 3.4f;
    String text = format.format(value);
    assertEquals("string: " + text, value, formatter.stringToValue(text));
}
 
开发者ID:RockManJoe64,项目名称:swingx,代码行数:16,代码来源:NumberEditorExtTest.java

示例13: testFloatStringToValueZero

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
 * Issue #1528-swingx: numbereditor doesn't allow negative values.
 * 
 * Test zero
 * 
 * @throws ParseException 
 */
@Test
public void testFloatStringToValueZero() throws ParseException {
    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new StrictNumberFormatter(format);
    formatter.setValueClass(Float.class);
    float value = 0f;
    String text = format.format(value);
    assertEquals("string: " + text, value, formatter.stringToValue(text));
}
 
开发者ID:RockManJoe64,项目名称:swingx,代码行数:17,代码来源:NumberEditorExtTest.java

示例14: testFloatStringToValueNegative

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
 * Issue #1528-swingx: numbereditor doesn't allow negative values.
 * 
 * Test negative
 * 
 * @throws ParseException 
 */
@Test
public void testFloatStringToValueNegative() throws ParseException {
    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new StrictNumberFormatter(format);
    formatter.setValueClass(Float.class);
    float value = -3.4f;
    String text = format.format(value);
    assertEquals("string: " + text, value, formatter.stringToValue(text));
}
 
开发者ID:RockManJoe64,项目名称:swingx,代码行数:17,代码来源:NumberEditorExtTest.java

示例15: testStrictNumberFormatterAutoRangeInteger

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
@Test (expected = ParseException.class)
public void testStrictNumberFormatterAutoRangeInteger() throws ParseException {
    NumberFormat format = NumberFormat.getIntegerInstance();
    NumberFormatter formatter = new StrictNumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.stringToValue(TOO_BIG_INTEGER);
}
 
开发者ID:RockManJoe64,项目名称:swingx,代码行数:8,代码来源:NumberEditorExtTest.java


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