JTextField设置位数校验,不正确不允许失去焦点

JTextField设置位数校验,不正确不允许失去焦点

JTextField.setInputVerifier(new Verifier(this,2));
package com.wxn.tempbom.create;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JTextField;

import com.teamcenter.rac.util.MessageBox;

public class Verifier extends InputVerifier {

	private int length;
	private JDialog dialog;
	public Verifier(JDialog dialog, int length) {
		this.dialog = dialog;
		this.length = length;
	}
	@Override
	public boolean verify(JComponent input) {
		JTextField tf = (JTextField)input;
		String text = tf.getText();
		if(text.length()>0&&text.length()

你可能感兴趣的:(java,SE)