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

The following are Jave code examples for showing how to use setPlaceholderCharacter() of the javax.swing.text.MaskFormatter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: cuba   File: DesktopTimeField.java   Source Code and License Vote up 6 votes
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
Project: cooper   File: AddIPDialog.java   Source Code and License Vote up 6 votes
public AddIPDialog(JDependCooper frame) throws ParseException {
	super();
	this.frame = frame;

	setSize(250, 100);
	this.setLocationRelativeTo(null);// 窗口在屏幕中间显示

	this.setLayout(new BorderLayout());

	MaskFormatter ipmask = new MaskFormatter("###.###.###.###");
	ipmask.setPlaceholderCharacter(' ');
	field = new JFormattedTextField(ipmask);
	field.setFont(new Font("Courier", Font.PLAIN, 18));
	field.setColumns(16);
	this.add(BorderLayout.CENTER, field);

	JPanel buttonPanel = new JPanel();
	buttonPanel.add(this.createOkButton());
	buttonPanel.add(this.createCloseButton());

	this.add(BorderLayout.SOUTH, buttonPanel);

}
 
Example 3
Project: fll-sw   File: ScheduleDurationField.java   Source Code and License Vote up 6 votes
/**
 * @param value the duration to use for the initial value, may not be null
 */
public ScheduleDurationField(final Duration value) {
  setInputVerifier(new TimeVerifier());

  try {
    final MaskFormatter mf = new MaskFormatter(MASKFORMAT);
    mf.setPlaceholderCharacter('_');
    mf.setValueClass(String.class);
    final DefaultFormatterFactory dff = new DefaultFormatterFactory(mf);
    setFormatterFactory(dff);
  } catch (final ParseException pe) {
    throw new FLLInternalException("Invalid format for MaskFormatter", pe);
  }

  setDuration(value);
}
 
Example 4
Project: fll-sw   File: ScheduleTimeField.java   Source Code and License Vote up 5 votes
/**
 * @param value the initial value for the widget
 */
public ScheduleTimeField(final LocalTime value) {
  try {
    final MaskFormatter mf = new MaskFormatter(MASKFORMAT);
    mf.setPlaceholderCharacter('_');
    mf.setValueClass(String.class);
    final DefaultFormatterFactory dff = new DefaultFormatterFactory(mf);
    setFormatterFactory(dff);
  } catch (final ParseException pe) {
    throw new FLLInternalException("Invalid format for MaskFormatter", pe);
  }

  setTime(value);
}
 
Example 5
Project: logisim-evolution   File: Pin.java   Source Code and License Vote up 4 votes
public EditText(Value value, RadixOption radix, int width) {
	super();
	String mask = "";
	GridBagConstraints gbc = new GridBagConstraints();
	MaskFormatter formatter = new MaskFormatter();
	DecimalFormat df = new DecimalFormat();
	JLabel label = new JLabel("");
	Color back = new Color(0xff, 0xf0, 0x99);

	setUndecorated(true);
	setModal(true);
	setLayout(new GridBagLayout());

	this.radix = radix;
	bitWidth = width;
	oldVal = value;
	// System.err.println("Wdth:"+bitWidth);

	try {
		formatter.setPlaceholderCharacter('_');
		if (radix == RadixOption.RADIX_16) {
			label.setText("0x");
			for (int i = 0; i < Math.ceil(bitWidth / 4.0); i++) {
				mask += "H";
			}
			formatter.setMask(mask);
			text = new JFormattedTextField(formatter);
			text.setText(value.toHexString());
		} else if (radix == RadixOption.RADIX_8) {
			label.setText("0");
			for (int i = 0; i < Math.ceil(bitWidth / 3.0); i++) {
				mask += "#";
			}
			formatter.setInvalidCharacters("89");
			formatter.setMask(mask);
			text = new JFormattedTextField(formatter);
			text.setText(value.toOctalString());
		} else if (radix == RadixOption.RADIX_10_SIGNED) {
			mask = "#;-#";
			df.setParseIntegerOnly(true);
			df.applyPattern(mask);
			df.setMaximumIntegerDigits(11);
			text = new JFormattedTextField(df);
			text.setColumns(11);
			// System.err.println("Val:" + value.toDecimalString(true));
			text.setText(value.toDecimalString(true));
		} else if (radix == RadixOption.RADIX_10_UNSIGNED) {
			mask = "#;";
			df.setParseIntegerOnly(true);
			df.applyPattern(mask);
			df.setMaximumIntegerDigits(10);
			text = new JFormattedTextField(df);
			text.setColumns(10);
			// System.err.println("Val:" +
			// value.toDecimalString(false));
			text.setText(value.toDecimalString(false));
		}
	} catch (ParseException ex) {
		Logger.getLogger(Pin.class.getName()).log(Level.SEVERE, null,
				ex);
	}

	gbc.gridx = gbc.gridy = 0;
	add(label, gbc);
	gbc.gridx = 1;
	gbc.gridwidth = GridBagConstraints.REMAINDER;
	gbc.anchor = GridBagConstraints.BASELINE;
	text.addKeyListener(this);
	text.setBorder(null);
	text.setBackground(back);
	add(text, gbc);

	pack();
}
 
Example 6
Project: Cine-Movies   File: Formatacoes.java   Source Code and License Vote up 4 votes
/** Inicializa os campos */
protected Formatacoes()
{
	try {
		cpf = new MaskFormatter("###.###.###-##");
		cpf.setPlaceholderCharacter('_');
		rg = new MaskFormatter("#########");
		rg.setPlaceholderCharacter('_');
		telefone = new MaskFormatter("####-####");
		telefone.setPlaceholderCharacter('_');
		telefone2 = new MaskFormatter("####-####");
		telefone2.setPlaceholderCharacter('_');
		data = new MaskFormatter("##/##/####");
		data.setPlaceholderCharacter('_');
		cep = new MaskFormatter("#####-###");
		cep.setPlaceholderCharacter('_');
		tipo = new MaskFormatter("U");
		tipo.setPlaceholder(" ");
		tipo.setValidCharacters("CFA");
	} catch (ParseException e) {
		JOptionPane.showMessageDialog(null,"ERRO: N�o foi poss�vel criar as m�scaras dos campos da janela.");
	}
}