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

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

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

NumberFormatter.setAllowsInvalid介绍

暂无

代码示例

代码示例来源: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: 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

NumberFormat integerFormat = NumberFormat.getIntegerInstance();
NumberFormatter formatter = new NumberFormatter(integerFormat);
formatter.setAllowsInvalid(false);
JFormattedTextField textfield = new JFormattedTextField(formatter);

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

NumberFormatter formatter = new NumberFormatter(); //create the formatter
formatter.setAllowsInvalid(false); //must specify that invalid chars are not allowed

JFormattedTextField field = new JFormattedTextField(formatter); //pass the formatter to the field

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

NumberFormat format = NumberFormat.getIntegerInstance();
 format.setGroupingUsed(false);
 NumberFormatter numberFormatter = new NumberFormatter(format);
 numberFormatter.setValueClass(Long.class); 
 numberFormatter.setAllowsInvalid(false); //this is the key
 JFormattedTextField jFormattedTextField = new JFormattedTextField(numberFormatter);

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

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);
myTextField = new JFormattedTextField(formatter);

代码示例来源: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: digital-preservation/droid

@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: 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: sing-group/GC4S

private AbstractFormatter configureFormatter() {
  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);
  return formatter;
}

代码示例来源:origin: org.boofcv/boofcv-swing

public static JFormattedTextField createTextField( double current , double min , double max ) {
    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Double.class);
    if( !Double.isNaN(min) )
      formatter.setMinimum(min);
    if( !Double.isNaN(max) )
      formatter.setMaximum(max);
    formatter.setAllowsInvalid(true);
//        formatter.setCommitsOnValidEdit(true);
    JFormattedTextField field = new JFormattedTextField(formatter);
    field.setHorizontalAlignment(JTextField.RIGHT);
    field.setValue(current);
    return field;
  }

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

NumberFormatter numberFormatter = new NumberFormatter( 
     NumberFormat.getIntegerInstance());
 // allow or not doesn't make a difference
 numberFormatter.setAllowsInvalid(false);  
 numberFormatter.setCommitsOnValidEdit(true);
 JFormattedTextField readTimeOut = new JFormattedTextField(numberFormatter);
 PropertyChangeListener l = new PropertyChangeListener() {
   @Override
   public void propertyChange(PropertyChangeEvent evt) {
     LOG.info("got new value: " + evt.getNewValue());
   }
 };
 readTimeOut.addPropertyChangeListener("value", l);
 readTimeOut.setColumns(20);
 readTimeOut.setHorizontalAlignment(SwingConstants.RIGHT);    
 JFormattedTextField other = new JFormattedTextField(numberFormatter);
 other.addPropertyChangeListener("value", l);
 other.setColumns(20);
 other.setHorizontalAlignment(SwingConstants.RIGHT);    
 JPanel box = new JPanel();
 box.add(readTimeOut);
 box.add(other);

代码示例来源:origin: org.boofcv/boofcv-swing

public static JFormattedTextField createTextField( int current , int min , int max ) {
    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.setMinimum(min);
    formatter.setMaximum(max);
    formatter.setAllowsInvalid(true);
//        formatter.setCommitsOnValidEdit(true);
    JFormattedTextField field = new JFormattedTextField(formatter);
    field.setHorizontalAlignment(JTextField.RIGHT);
    field.setValue(current);
    return field;
  }

代码示例来源:origin: Exslims/MercuryTrade

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

代码示例来源:origin: girtel/Net2Plan

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

代码示例来源:origin: PortSwigger/distribute-damage

ConfigurableSettings() {
  settings = new LinkedHashMap<>();
  put("throttle", 1000);
  put("max param length", 30);
  put("scan path", true);
  put("scan cookies", true);
  put("scan headers", true);
  put("target headers", "User-Agent,Referer");
  put("header target mime types", "HTML,JSON");
  put("header target status codes", "200,302,307");
  for(String key: settings.keySet()) {
    //Utilities.callbacks.saveExtensionSetting(key, null); // purge saved settings
    String value = Utilities.callbacks.loadExtensionSetting(key);
    if (Utilities.callbacks.loadExtensionSetting(key) != null) {
      putRaw(key, value);
    }
  }
  NumberFormat format = NumberFormat.getInstance();
  onlyInt = new NumberFormatter(format);
  onlyInt.setValueClass(Integer.class);
  onlyInt.setMinimum(-1);
  onlyInt.setMaximum(Integer.MAX_VALUE);
  onlyInt.setAllowsInvalid(false);
}

代码示例来源:origin: PortSwigger/backslash-powered-scanner

ConfigurableSettings() {
  settings = new LinkedHashMap<>();
  put("thorough mode", false);
  put("confirmations", 8);
  put("encode everything", false);
  put("debug", false);
  put("try transformation scan", false);
  put("try diffing scan", true);
  put("diff: HPP", true);
  put("diff: HPP auto-followup", false);
  put("diff: syntax attacks", true);
  put("diff: value preserving attacks", true);
  put("diff: experimental concat attacks", false);
  put("diff: magic value attacks", true);
  put("diff: magic values", "undefined,null,empty,none,COM1,c!C123449477,aA1537368460!");
  for(String key: settings.keySet()) {
    //Utilities.callbacks.saveExtensionSetting(key, null); // purge saved settings
    String value = Utilities.callbacks.loadExtensionSetting(key);
    if (Utilities.callbacks.loadExtensionSetting(key) != null) {
      putRaw(key, value);
    }
  }
  NumberFormat format = NumberFormat.getInstance();
  onlyInt = new NumberFormatter(format);
  onlyInt.setValueClass(Integer.class);
  onlyInt.setMinimum(-1);
  onlyInt.setMaximum(Integer.MAX_VALUE);
  onlyInt.setAllowsInvalid(false);
}

相关文章