Ok, this may sound simple but still troubles me. I use a jtextarea and a document filter. I'd like as soon as the user presses "a" for example just the current text to be printed via println. I use:
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
if ("a".equals(text)) {
String c = fb.toString();
System.out.println(c);
}
super.replace(fb, offset, length, text, attrs);
}
}
I type "help", for example and get javax.swing.text.AbstractDocument$DefaultFilterBypass@6f9bb25a in console! But why? D: Thanks a lot
Use
String c = fb.getDocument().getText(0, fb.getDocument().getLength());
You're currently printing the FilterBypass object. You need to get the Document and get the text by passing the offset and the length of the document