Package javax.swing

Examples of javax.swing.JFormattedTextField$AbstractFormatter


    public FormattedCellEditor(AbstractFormatterFactory factory) {
        super(new JFormattedTextField(factory));
        df = (JFormattedTextField)getComponent();
    }
    public FormattedCellEditor(DocumentFilter filter) {
        super(new JFormattedTextField(filter));
        df = (JFormattedTextField)getComponent();
        ((DataFieldFormatter)df.getFormatter()).setFilter(filter);
        ((DataFieldFormatter)df.getFormatter()).install(df);
    }
View Full Code Here


          // System.out.println("Initial text = " + text);
//          String charsToRemove;
          // If the user is trying to backspace over a special character, like a comma, we don't
          // allow it, but instead move to the previous number. This only applies if the dot and mark
          // of the filter are the same (ie, they don't have a highlighted selection)
          JFormattedTextField comp = this.field;
          if (length == 1 && comp.getCaret().getDot() == comp.getCaret().getMark()) {
            while (offset >= 0 && !Character.isDigit(text.charAt(offset))) {
              offset--;
            }
            if (offset < 0) {
              // Nothing to do
              return;
            }
//            else {
//              charsToRemove = text.substring(offset, offset + length);
//            }
          }
//          else {
//             charsToRemove = text.substring(offset, offset + length);
//          }
          // System.out.println("Chars to remove = " + charsToRemove);
          try {
          Object o = comp.getFormatter().stringToValue(text);
          String value = text;
          // TF:11/04/2008: Check for null coming back in case it's a widget mapped to
          // a nullable field with a null value
          if (o != null) {
            value = o.toString();
            // System.out.println(o.toString() + " - " + o.getClass().toString());
            char[] chars = text.toCharArray();
            int srcIndex = offset-1;
            int destIndex = offset + length-1;
            while (destIndex >= 0) {
              if (Character.isDigit(chars[destIndex])) {
                //need to replace this digit with another one
                while (srcIndex >= 0 && !Character.isDigit(chars[srcIndex])) {
                  srcIndex--;
                }
                if (srcIndex >= 0) {
                  // Replace this index with the source digit
                  chars[destIndex] = chars[srcIndex];
                  // Now drop the source index back one
                  srcIndex--;
                }
                else {
                  // No character, must replace with 0
                  chars[destIndex] = '0';
                }
              }
              destIndex--;
            }
            // System.out.println("Current dot at:" + this.field.getCaret().getDot());
            // System.out.println("Current mark at:" + this.field.getCaret().getMark());
            // System.out.println("New value = " + new String(chars));
            o = comp.getFormatter().stringToValue(new String(chars));
          }
          value = comp.getFormatter().valueToString(o);
              int lengthToReplace = getReplaceToOffset(text, value);
             
              lengthToReplace = Math.max(length + offset, lengthToReplace);
              // System.out.println("new value = " + value);
              // System.out.println("replacement length(" + text + ", " + value + ") = " + lengthToReplace);
View Full Code Here

     * @throws NullPointerException if the valueModel is <code>null</code>
     */
    public static JFormattedTextField createFormattedTextField(
        ValueModel valueModel,
        Format format) {
        JFormattedTextField textField = new JFormattedTextField(format);
        Bindings.bind(textField, valueModel);
        return textField;
    }
View Full Code Here

     * @throws NullPointerException if the valueModel is <code>null</code>
     */
    public static JFormattedTextField createFormattedTextField(
        ValueModel valueModel,
        JFormattedTextField.AbstractFormatter formatter) {
        JFormattedTextField textField = new JFormattedTextField(formatter);
        Bindings.bind(textField, valueModel);
        return textField;
    }
View Full Code Here

     * @throws NullPointerException if the valueModel is <code>null</code>
     */
    public static JFormattedTextField createFormattedTextField(
        ValueModel valueModel,
        JFormattedTextField.AbstractFormatterFactory formatterFactory) {
        JFormattedTextField textField = new JFormattedTextField(formatterFactory);
        Bindings.bind(textField, valueModel);
        return textField;
    }
View Full Code Here

        try {
            formatter = new MaskFormatter(mask);   
        } catch (ParseException e) {
            throw new UsageException("Invalid mask '" + mask + "'.");
        }
        JFormattedTextField textField = new JFormattedTextField(formatter);
        Bindings.bind(textField, valueModel);
        return textField;
    }
View Full Code Here

          if (table != null) {
            if (ArrayFieldCellHelper.getArrayEditorComponent(table) == focusOwner) {
              // TF:08/06/2008:LIB-17:If this is a formatted field, we must use the getValue method,
              // otherwise we will potentially have formatting errors on masked fields.
              if (focusOwner instanceof JFormattedTextField) {
                JFormattedTextField formattedField = (JFormattedTextField)focusOwner;
                try {
                  formattedField.commitEdit();
                  //GK/DK: convert column index to a model index to set value
                  table.setValueAt(formattedField.getValue(), table.getEditingRow(), table.getEditingColumn());
                }
                catch (ParseException e) {
                  _log.error("Unhandled parse exception committing field edit: ", e);
                }
              }
View Full Code Here

//            }
//        });
    }
   
    public PasswordCellEditor(AbstractFormatter formatter) {
        super(new JFormattedTextField(formatter));
        df = (JFormattedTextField)getComponent();
        df.setFocusLostBehavior(JFormattedTextField.PERSIST);
    }
View Full Code Here

        super(new JFormattedTextField(formatter));
        df = (JFormattedTextField)getComponent();
        df.setFocusLostBehavior(JFormattedTextField.PERSIST);
    }
    public PasswordCellEditor(AbstractFormatterFactory factory) {
        super(new JFormattedTextField(factory));
        df = (JFormattedTextField)getComponent();
    }
View Full Code Here

     */
    public class ValidatingJTextFieldCellEditor extends DefaultCellEditor {
        /** Construct a validating JTextField JTable Cell editor.
         */
        public ValidatingJTextFieldCellEditor() {
            super(new JFormattedTextField());
        }
View Full Code Here

TOP

Related Classes of javax.swing.JFormattedTextField$AbstractFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.