Блокировка\удаление ведущих нулей в поле TextField

Ребятушки ,помогите пожалуйста, нужно блокировать ввод ведущих нулей программисту-пользователю и удалять ведущие нули в TextField,то есть чтобы они даже не вводились.Пример:user пишет в TextField "000012345"-->нажимаем кнопочку,магия-->брык,TextField становится "12345".У меня пока не получается, в бошку засунуть всё , пока ток так.

Юзаю это:

тра-та-та код

public JTextField cntrlVControlInput(JTextField temp) { if (temp.getDocument() instanceof AbstractDocument) ((AbstractDocument) temp.getDocument()).setDocumentFilter(new SpaceDocumentFilter()); return temp; }

тра-та-та код

юзаю этот класс: public class SpaceDocumentFilter extends DocumentFilter {

    public SpaceDocumentFilter() {
    }

    public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr)
            throws BadLocationException {
        if (string == null)
            return;
        replace(fb, offset, 0, string, attr);
    }

    public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException {
        replace(fb, offset, length, "", null);
    }

    public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
            throws BadLocationException {
        fb.replace(offset, length, checkInput(text, offset), attrs);
    }

    private String checkInput(String proposedValue, int offset) throws BadLocationException {
        return proposedValue.replaceAll("", "");
    }//^0+
    //^0+(?=\\\\d+$)
}

//[\s\\/'/"!~@#$№%^&*()_+=><:;.,\\[\\]{}^] - это на всё лишнее //^0+ - перед этим if на ("\d+") //^0+(?=\d+$)-последние две регулярочки в иннете откопал : [url]https://stackoverrun.com/ru/q/4314720[/url]

/тра-та-та еще код/

//еще это юзаю public JTextField inputCheck(JTextField temp) {

    temp.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(KeyEvent e) {

            char key = e.getKeyChar();

            if (Character.isWhitespace(key))
                e.consume();
            if ((key == '!' || (key == '~') || (key == '@') || (key == '#') || (key == '?') || (key == '$')
                    || (key == '%') || (key == '^') || (key == '&') || (key == '*') || (key == '(') || (key == ')')
                    || (key == '_') || (key == '+') || (key == '=') || (key == '-') || (key == '<') || (key == '>')
                    || (key == ':') || (key == ';') || (key == '.') || (key == '\\') || (key == '|') || (key == '[')
                    || (key == ']') || (key == '"') || (key == '\'') || (key == '}') || (key == '{')))
                e.consume();
            if (Character.isAlphabetic(key))
                e.consume();

            if (temp.getText().length() >= 10)
                e.consume();
        }
    });
    return temp;
}

тра-та-та еще кода чутка

Братцы выручайте,помогите)Очень прошу


Ответы (0 шт):