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


Java NumberFormatter.setOverwriteMode方法代码示例

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


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

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

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

示例3: IntegerCellEditor

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
 * Constructor.
 * @param min the minimum of valid values.
 * @param max the maximum of valid values. 
 */
public IntegerCellEditor(int min, int max) {
    super(new JFormattedTextField());
    textField = (JFormattedTextField) getComponent();
    minimum = new Integer(min);
    maximum = new Integer(max);

    // Set up the editor for the integer cells.
    integerFormat = NumberFormat.getIntegerInstance();
    NumberFormatter intFormatter = new NumberFormatter(integerFormat);
    intFormatter.setFormat(integerFormat);
    intFormatter.setOverwriteMode(false);
    intFormatter.setMinimum(minimum);
    intFormatter.setMaximum(maximum);

    textField.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
    textField.setValue(minimum);
    textField.setHorizontalAlignment(JTextField.TRAILING);
    textField.setFocusLostBehavior(JFormattedTextField.PERSIST);

    // React when the user presses Enter while the editor is
    // active.  (Tab is handled as specified by
    // JFormattedTextField's focusLostBehavior property.)
    textField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
    textField.getActionMap().put("check", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!textField.isEditValid()) { //The text is invalid.
                Toolkit.getDefaultToolkit().beep();
                textField.selectAll();
            } else {
                try {              //The text is valid,
                    textField.commitEdit();     //so use it.
                    textField.postActionEvent(); //stop editing
                } catch (java.text.ParseException ex) {
                }
            }
        }
    });
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:46,代码来源:IntegerCellEditor.java

示例4: DoubleCellEditor

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
 * Constructor.
 * @param min the minimum of valid values.
 * @param max the maximum of valid values. 
 */
public DoubleCellEditor(double min, double max) {
    super(new JFormattedTextField());
    textField = (JFormattedTextField) getComponent();
    minimum = new Double(min);
    maximum = new Double(max);

    // Set up the editor for the double cells.
    doubleFormat = NumberFormat.getNumberInstance();
    NumberFormatter doubleFormatter = new NumberFormatter(doubleFormat);
    doubleFormatter.setFormat(doubleFormat);
    doubleFormatter.setOverwriteMode(false);
    doubleFormatter.setMinimum(minimum);
    doubleFormatter.setMaximum(maximum);

    textField.setFormatterFactory(new DefaultFormatterFactory(doubleFormatter));
    textField.setValue(minimum);
    textField.setHorizontalAlignment(JTextField.TRAILING);
    textField.setFocusLostBehavior(JFormattedTextField.PERSIST);

    // React when the user presses Enter while the editor is
    // active.  (Tab is handled as specified by
    // JFormattedTextField's focusLostBehavior property.)
    textField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
    textField.getActionMap().put("check", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!textField.isEditValid()) { //The text is invalid.
                Toolkit.getDefaultToolkit().beep();
                textField.selectAll();
            } else {
                try {              //The text is valid,
                    textField.commitEdit();     //so use it.
                    textField.postActionEvent(); //stop editing
                } catch (java.text.ParseException ex) {
                }
            }
        }
    });
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:46,代码来源:DoubleCellEditor.java

示例5: newNumberFormatter

import javax.swing.text.NumberFormatter; //导入方法依赖的package包/类
/**
 * @param pattern       The pattern to use (e.g. "#,##0.000000000000000")
 * @param decimalPlaces The number of decimal places to allow
 * @param maxLength     The overall maximum length
 * @return A number formatter configured for insert mode and enforced maximum length length
 */
private static NumberFormatter newNumberFormatter(String pattern, int decimalPlaces, int maxLength) {

    DecimalFormat decimalFormat = newDecimalFormat(pattern, decimalPlaces);

    NumberFormatter numberFormatter = newNumberFormatter(decimalFormat, maxLength);

    // Ensure we keep insert mode
    numberFormatter.setOverwriteMode(false);

    return numberFormatter;

}
 
开发者ID:bither,项目名称:bither-desktop-java,代码行数:19,代码来源:Numbers.java


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