當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。