javax.swing.text.NumberFormatter.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中javax.swing.text.NumberFormatter.<init>()方法的一些代码示例,展示了NumberFormatter.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NumberFormatter.<init>()方法的具体详情如下:
包路径:javax.swing.text.NumberFormatter
类名称:NumberFormatter
方法名:<init>

NumberFormatter.<init>介绍

暂无

代码示例

代码示例来源:origin: ballerina-platform/ballerina-lang

public TimeoutGUI() {
  rows = Timeout.getTimeoutsJava().entrySet().stream().map(e -> {
    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new NumberFormatter(format);
    format.setGroupingUsed(false);
    formatter.setValueClass(Integer.class);
    formatter.setMinimum(0);
    formatter.setAllowsInvalid(true);
    formatter.setMaximum(Integer.MAX_VALUE);
    final JFormattedTextField field = new JFormattedTextField(formatter);
    field.setToolTipText(FIELD_TOOLTIP);
    field.setText(e.getValue().toString());
    return new AbstractMap.SimpleEntry<>(e.getKey(), field);
  }).collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
  rootPanel = createRootPanel();
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  NumberFormat format = NumberFormat.getInstance();
  NumberFormatter formatter = new NumberFormatter(format);
  formatter.setValueClass(Integer.class);
  formatter.setMinimum(0);
  formatter.setMaximum(Integer.MAX_VALUE);
  formatter.setAllowsInvalid(false);
  // If you want the value to be committed on each keystroke instead of focus lost
  formatter.setCommitsOnValidEdit(true);
  JFormattedTextField field = new JFormattedTextField(formatter);

  JOptionPane.showMessageDialog(null, field);

  // getValue() always returns something valid
  System.out.println(field.getValue());
}

代码示例来源:origin: tomighty/tomighty

public IntegerFormatter(int minValue) {
  this.minValue = minValue;
  numberFormatter = new NumberFormatter(NumberFormat.getIntegerInstance());
}

代码示例来源:origin: stackoverflow.com

NumberFormatter nf = new NumberFormatter();
nf.setValueClass(Integer.class);
nf.setMinimum(new Integer(0));
nf.setMaximum(new Integer(100));

JFormattedTextField field = new JFormattedTextField(nf);

代码示例来源:origin: stackoverflow.com

NumberFormat longFormat = NumberFormat.getIntegerInstance();

NumberFormatter numberFormatter = new NumberFormatter(longFormat);
numberFormatter.setValueClass(Long.class); //optional, ensures you will always get a long value
numberFormatter.setAllowsInvalid(false); //this is the key!!
numberFormatter.setMinimum(0l); //Optional

JFormattedTextField field = new JFormattedTextField(numberFormatter);

代码示例来源:origin: winterDroid/android-drawable-importer-intellij-plugin

private void createUIComponents() {
    NumberFormat format = NumberFormat.getIntegerInstance();
    NumberFormatter numberFormatter = new NumberFormatter(format);
    numberFormatter.setValueClass(Integer.class);
    numberFormatter.setAllowsInvalid(false);
    numberFormatter.setMinimum(1);
    numberFormatter.setCommitsOnValidEdit(true);

    targetHeight = new JFormattedTextField(numberFormatter);
    targetWidth = new JFormattedTextField(numberFormatter);
    targetRoot = new FileBrowserField(FileBrowserField.RESOURCE_DIR_CHOOSER);
  }
}

代码示例来源:origin: stackoverflow.com

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);
   }

代码示例来源:origin: stackoverflow.com

//Locale myLocale = Locale.GERMANY;  //... or better, the current Locale
Locale myLocale = Locale.getDefault(); // better still
NumberFormat numberFormatB = NumberFormat.getInstance(myLocale);
numberFormatB.setMaximumFractionDigits(2);
numberFormatB.setMinimumFractionDigits(2);
numberFormatB.setMinimumIntegerDigits(1);
edit.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
         new NumberFormatter(numberFormatB)));

代码示例来源:origin: stackoverflow.com

jftSourceWidth.setText("0.0000");
jftSourceWidth.setHorizontalAlignment(SwingConstants.CENTER);
jftSourceWidth.setBounds(51, 69, 57, 20);
jftSourceWidth.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new     javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.0000"))));
pnSource.add(jftSourceWidth);

代码示例来源:origin: stackoverflow.com

// Define the number factory.
NumberFormat nf = NumberFormat.getIntegerInstance(); // Specify specific format here.
NumberFormatter nff = new NumberFormatter(nf);
DefaultFormatterFactory factory = new DefaultFormatterFactory(nff);

// Define the decimal factory.
DecimalFormat df = new DecimalFormat(); // And here..
NumberFormatter dnff = new NumberFormatter(df);
DefaultFormatterFactory factory2 = new DefaultFormatterFactory(dnff); 

// Then you set which factory to use.
JFormattedTextField field = new JFormattedTextField();
field.setFormatterFactory(factory);
//field.setFormatterFactory(factory2);

代码示例来源:origin: coova/jradius

/**
 * @return Returns the numberFormatter.
 */
public NumberFormatter getNumberFormatter()
{
  if (numberFormatter == null)
  {
    numberFormatter = new NumberFormatter(NumberFormat.getIntegerInstance());
    numberFormatter.setValueClass(Integer.class);
  }
  return numberFormatter;
}

代码示例来源:origin: com.hynnet/jradius-extended

/**
 * @return Returns the numberFormatter.
 */
public NumberFormatter getNumberFormatter()
{
  if (numberFormatter == null)
  {
    numberFormatter = new NumberFormatter(NumberFormat.getIntegerInstance());
    numberFormatter.setValueClass(Integer.class);
  }
  return numberFormatter;
}

代码示例来源:origin: MarginallyClever/Makelangelo-software

protected void createAndAttachFormatter(Locale locale) {
  NumberFormat nFloat = NumberFormat.getNumberInstance(locale);
  nFloat.setMinimumFractionDigits(1);
  nFloat.setMaximumFractionDigits(3);
  nFloat.setGroupingUsed(false);
  
  NumberFormatter nff = new NumberFormatter(nFloat);
  DefaultFormatterFactory factory = new DefaultFormatterFactory(nff);
  setFormatterFactory(factory);
}

代码示例来源:origin: stackoverflow.com

NumberFormatter nf = new NumberFormatter();  
nf.setMinimum(new Integer(0));  
nf.setMaximum(new Integer(8));  
JFormattedTextField field = new JFormattedTextField(nf);

代码示例来源:origin: org.cytoscape/filter2-impl

public static NumberFormatter createNumberFormatter() {
  NumberFormat format = NumberFormat.getNumberInstance();
  NumberFormatter formatter = new NumberFormatter(format);
  formatter.setValueClass(Double.class);
  formatter.setCommitsOnValidEdit(true);
  return formatter;
}

代码示例来源:origin: nroduit/Weasis

public static DefaultFormatterFactory setPreciseDoubleFormat(double min, double max) {
    NumberFormatter displayFormatter = new NumberFormatter(new DecimalFormat("#,##0.##")); //$NON-NLS-1$
    displayFormatter.setValueClass(Double.class);
    NumberFormatter editFormatter = new NumberFormatter(new DecimalFormat("#,##0.0#############")); //$NON-NLS-1$
    editFormatter.setValueClass(Double.class);
    editFormatter.setMinimum(min);
    editFormatter.setMaximum(max);
    editFormatter.setAllowsInvalid(true);
    return new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);
  }
}

代码示例来源:origin: uk.gov.nationalarchives/droid-ui

@Override
  public AbstractFormatter getFormatter(JFormattedTextField tf) {
    NumberFormatter formatter = new NumberFormatter(new DecimalFormat("#0"));
    formatter.setValueClass(Integer.class);
    formatter.setAllowsInvalid(true);
    formatter.setCommitsOnValidEdit(false);
    formatter.setMinimum(0);
    return formatter;
  };
}

代码示例来源:origin: stackoverflow.com

NumberFormat format = NumberFormat.getCurrencyInstance(Locale.US);
format.setMaximumFractionDigits(0);

NumberFormatter formatter = new NumberFormatter(format);
formatter.setMinimum(5.0);
formatter.setMaximum(10000000.0);
formatter.setAllowsInvalid(false);
formatter.setOverwriteMode(true);

JFormattedTextField field = new JFormattedTextField(formatter);
field.setValue(5.0);

代码示例来源:origin: org.cytoscape/filter2-impl

public static NumberFormatter createIntegerFormatter(int minimum, int maximum) {
  NumberFormat format = NumberFormat.getIntegerInstance();
  NumberFormatter formatter = new NumberFormatter(format);
  formatter.setMinimum(minimum);
  formatter.setMaximum(maximum);
  formatter.setValueClass(Integer.class);
  formatter.setCommitsOnValidEdit(true);
  return formatter;
}

代码示例来源:origin: stackoverflow.com

public static final int DECIMAL_PLACES = 2;

NumberFormatter formatter = new NumberFormatter(DECIMAL_PLACES);

String value = formatter.format(9.319); // "9,32"
String value2 = formatter.format(0.0000005); // "5,00E-7"
String value3 = formatter.format(1324134123); // "1,32E9"

double parsedValue1 = formatter.parse("0,4E-2", 0); // 0.004
double parsedValue2 = formatter.parse("0,002", 0); // 0.002
double parsedValue3 = formatter.parse("3423,12345", 0); // 3423.12345

相关文章