Portál AbcLinuxu, 11. května 2024 07:34
Řešení dotazu:
.. .. public void insertString(FilterBypass fb, int offs, String str, AttributeSet a) throws BadLocationException { String text = fb.getDocument().getText(0, fb.getDocument().getLength()); text += str; if ((fb.getDocument().getLength() + str.length()) < getFilterParams().getMaxCharacters() && text.matches(getFilterParams().getStringMatches())) { super.insertString(fb, offs, str, a); } else { Toolkit.getDefaultToolkit().beep(); } } ...
private Pattern pattern; ... public Pattern getPattern() { if (pattern == null) pattern = Pattern.compile(getFilterParams().getStringMatches()); return pattern; } public boolean matchInputString(String s) { Matcher matcher = getPattern().matcher(s); return matcher.matches() || matcher.hitEnd(); } ...
Tiskni Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.