Java Code Examples for javax.swing.text.MaskFormatter#setPlaceholderCharacter()

The following examples show how to use javax.swing.text.MaskFormatter#setPlaceholderCharacter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DesktopTimeField.java    From cuba with Apache License 2.0 6 votes vote down vote up
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"));
}
 
Example 2
Source File: HexValue4Field.java    From zxpoly with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: HexValue2Field.java    From zxpoly with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
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));
}