Есть ли способ обнаружить, когда нажата клавиша обратного пробела на клавиатуре, используя фильтр документов? The following is an edited code extract from hereОбнаружение нажатия клавиши backspace
Для примера
public class IntFilter extends DocumentFilter {
boolean trueFalse = true;
public void insertString(DocumentFilter.FilterBypass fb, int offset,
String string, AttributeSet attr)
throws BadLocationException {
StringBuffer buffer = new StringBuffer(string);
for (int i = buffer.length() - 1; i >= 0; i--) {
char ch = buffer.charAt(i);
if (!Character.isDigit(ch)) {
buffer.deleteCharAt(i);
trueFalse = false;
}
/*
else if (backspace pressed)
{
trueFalse = true;
}
*/
else{
trueFalse = true;
}
}
super.insertString(fb, offset, buffer.toString(), attr);
}
public void replace(DocumentFilter.FilterBypass fb,
int offset, int length, String string, AttributeSet attr) throws BadLocationException {
if (length > 0) fb.remove(offset, length);
insertString(fb, offset, string, attr);
}
}
Нужно ли использовать фильтр документов? – nom
@NabeelOmer За этот вопрос да. В реальной программе я в настоящее время экспериментирую с DocumentListener – Dan