类javax.swing.text.MaskFormatter源码实例Demo

下面列出了怎么用javax.swing.text.MaskFormatter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netbeans   文件: FormatSelector.java
/**
 * Returns format's pattern. 
 * 
 * @return format's pattern.
 */
public String getFormat() {
    if (format != null) return format;
    String fmt = null;
    if (formatter instanceof MaskFormatter) {
        fmt = ((MaskFormatter)formatter).getMask();
    } else if (formatter instanceof InternationalFormatter) {
        Format f = ((InternationalFormatter)formatter).getFormat();
        if (f instanceof DecimalFormat) {
            fmt = ((DecimalFormat)f).toPattern();
        } else if (f instanceof SimpleDateFormat) {
            fmt = ((SimpleDateFormat)f).toPattern();
        }
    }
    return fmt;
}
 
源代码2 项目: cuba   文件: DesktopTimeField.java
public DesktopTimeField() {
    UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);

    digitWidth = getDigitWidth();

    timeFormat = Datatypes.getFormatStringsNN(uss.getLocale()).getTimeFormat();
    resolution = DateField.Resolution.MIN;
    formatter = new MaskFormatter();
    formatter.setPlaceholderCharacter('_');
    impl = new FlushableFormattedTextField(formatter);
    FieldListener listener = new FieldListener();
    impl.addFocusListener(listener);
    impl.addKeyListener(listener);

    setShowSeconds(timeFormat.contains("ss"));
}
 
源代码3 项目: zxpoly   文件: HexValue4Field.java
public HexValue4Field() {
  super();
  final JFormattedTextField.AbstractFormatter FORMAT;
  try {
    final MaskFormatter formatter = new MaskFormatter("HHHH");
    formatter.setPlaceholderCharacter('0');
    formatter.setValidCharacters(ALLOWED_CHARS);
    formatter.setAllowsInvalid(false);
    FORMAT = formatter;
  } catch (ParseException ex) {
    throw new Error("Can't prepare formatter", ex);
  }

  setFormatter(FORMAT);
  refreshTextValue();
}
 
源代码4 项目: zxpoly   文件: HexValue2Field.java
public HexValue2Field() {
  super();
  final JFormattedTextField.AbstractFormatter FORMAT;
  try {
    final MaskFormatter formatter = new MaskFormatter("HH");
    formatter.setValidCharacters(ALLOWED_CHARS);
    formatter.setPlaceholderCharacter('0');
    formatter.setAllowsInvalid(false);
    FORMAT = formatter;
  } catch (ParseException ex) {
    throw new Error("Can't prepare formatter", ex);
  }

  setFormatter(FORMAT);
  refreshTextValue();
}
 
源代码5 项目: arcusplatform   文件: Fields.java
public static FormattedTextFieldBuilder<String> formattedTextFieldBuilder(String mask) {
   try {
      return new FormattedTextFieldBuilder<String>(new MaskFormatter(mask));
   }
   catch(ParseException e) {
      throw new IllegalArgumentException("Invalid mask: " + mask, e);
   }
}
 
源代码6 项目: dctb-utfpr-2018-1   文件: Register.java
/**
 * Creates new form Register
 */
public Register() {
   
    try {
        MaskFormatter maskData = new MaskFormatter("##/##/####");
        maskData.install(txtDataFormatada);
        initComponents();
    } catch (ParseException e) {
        e.printStackTrace();
    } 
      
}
 
源代码7 项目: java-swing-tips   文件: MainPanel.java
private MainPanel() {
  super(new BorderLayout());
  Box box = Box.createVerticalBox();
  box.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));

  String mask = "###-####";

  MaskFormatter formatter0 = createFormatter(mask);
  JFormattedTextField field0 = new JFormattedTextField(formatter0);
  box.add(makeTitledPanel("new MaskFormatter(\"###-####\")", field0));
  box.add(Box.createVerticalStrut(15));

  MaskFormatter formatter1 = createFormatter(mask);
  formatter1.setPlaceholderCharacter('_');
  JFormattedTextField field1 = new JFormattedTextField(formatter1);

  MaskFormatter formatter2 = createFormatter(mask);
  formatter2.setPlaceholderCharacter('_');
  formatter2.setPlaceholder("000-0000");
  JFormattedTextField field2 = new JFormattedTextField(formatter2);
  box.add(makeTitledPanel("MaskFormatter#setPlaceholderCharacter('_')", field1));
  box.add(Box.createVerticalStrut(15));

  Font font = new Font(Font.MONOSPACED, Font.PLAIN, 18);
  Insets insets = new Insets(1, 1 + 18 / 2, 1, 1);
  Stream.of(field0, field1, field2).forEach(tf -> {
    tf.setFont(font);
    tf.setColumns(mask.length() + 1);
    tf.setMargin(insets);
  });
  box.add(makeTitledPanel("MaskFormatter#setPlaceholder(\"000-0000\")", field2));
  box.add(Box.createVerticalGlue());

  add(box, BorderLayout.NORTH);
  setPreferredSize(new Dimension(320, 240));
}
 
源代码8 项目: java-swing-tips   文件: MainPanel.java
private MainPanel() {
  super(new BorderLayout());
  MaskFormatter formatter = createFormatter("UUUUUUUUUU");
  // formatter.setAllowsInvalid(true);
  // formatter.setCommitsOnValidEdit(true);
  // formatter.setPlaceholder("_");
  // formatter.setPlaceholderCharacter('?');

  JFormattedTextField field1 = new JFormattedTextField(formatter);
  field1.setFocusLostBehavior(JFormattedTextField.REVERT);

  JFormattedTextField field2 = new JFormattedTextField(formatter);
  field2.setFocusLostBehavior(JFormattedTextField.COMMIT);

  JFormattedTextField field3 = new JFormattedTextField(formatter);
  field3.setFocusLostBehavior(JFormattedTextField.PERSIST);

  JCheckBox check = new JCheckBox("setCommitsOnValidEdit");
  check.addActionListener(e -> formatter.setCommitsOnValidEdit(((JCheckBox) e.getSource()).isSelected()));

  Box box = Box.createVerticalBox();
  box.add(makeTitledPanel("COMMIT_OR_REVERT(default)", new JFormattedTextField(formatter)));
  box.add(Box.createVerticalStrut(5));
  box.add(makeTitledPanel("REVERT", field1));
  box.add(Box.createVerticalStrut(5));
  box.add(makeTitledPanel("COMMIT", field2));
  box.add(Box.createVerticalStrut(5));
  box.add(makeTitledPanel("PERSIST", field3));
  box.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  add(box, BorderLayout.NORTH);
  add(check, BorderLayout.SOUTH);
  setPreferredSize(new Dimension(320, 240));
}
 
源代码9 项目: weblaf   文件: JFormattedTextFieldExample.java
/**
 * Returns sample formatter.
 *
 * @param mask formatter mask
 * @return sample formatter
 */
protected static MaskFormatter createFormatter ( final String mask )
{
    try
    {
        return new MaskFormatter ( mask );
    }
    catch ( final ParseException e )
    {
        throw new RuntimeException ( "Unable to parse formatter mask: " + mask, e );
    }
}
 
源代码10 项目: weblaf   文件: WebFormattedTextFieldExample.java
/**
 * Returns sample formatter.
 *
 * @param mask formatter mask
 * @return sample formatter
 */
protected static MaskFormatter createFormatter ( final String mask )
{
    try
    {
        return new MaskFormatter ( mask );
    }
    catch ( final ParseException e )
    {
        throw new RuntimeException ( "Unable to parse formatter mask: " + mask, e );
    }
}
 
源代码11 项目: eplmp   文件: Tools.java
public static String increaseId(String id, String mask) throws ParseException {
    LOGGER.info("#### Tools.increaseId id = " + id + " , mask = " + mask);
    MaskFormatter formatter = new MaskFormatter(mask);
    formatter.setValueContainsLiteralCharacters(false);
    String value = formatter.stringToValue(id).toString();
    StringBuilder newValue = new StringBuilder();
    boolean increase = true;
    for (int i = value.length() - 1; i >= 0; i--) {
        char c = value.charAt(i);
        switch (c) {
            case '9':
                newValue.append((increase) ? '0' : '9');
                break;

            case '8':
                newValue.append((increase) ? '9' : '8');
                increase = false;
                break;

            case '7':
                newValue.append((increase) ? '8' : '7');
                increase = false;
                break;

            case '6':
                newValue.append((increase) ? '7' : '6');
                increase = false;
                break;

            case '5':
                newValue.append((increase) ? '6' : '5');
                increase = false;
                break;

            case '4':
                newValue.append((increase) ? '5' : '4');
                increase = false;
                break;

            case '3':
                newValue.append((increase) ? '4' : '3');
                increase = false;
                break;

            case '2':
                newValue.append((increase) ? '3' : '2');
                increase = false;
                break;

            case '1':
                newValue.append((increase) ? '2' : '1');
                increase = false;
                break;

            case '0':
                newValue.append((increase) ? '1' : '0');
                increase = false;
                break;

            default:
                newValue.append(c);
                break;
        }
    }
    return formatter.valueToString(newValue.reverse().toString());
}
 
源代码12 项目: cuba   文件: DesktopTimeField.java
public FlushableFormattedTextField(MaskFormatter formatter) {
    super(formatter);
}
 
 类所在包
 类方法
 同包方法