好吧,这听起来可能很简单,但仍然困扰着我。我使用一个jtextarea和一个文档过滤器。例如,只要用户按下"a“,我就希望通过println打印当前文本。我用:
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);
}
}例如,我输入“帮助”,并在控制台中获取javax.swing.text.AbstractDocument$DefaultFilterBypass@6f9bb25a!但是为什么呢?D:非常感谢
发布于 2014-04-20 19:40:39
使用
String c = fb.getDocument().getText(0, fb.getDocument().getLength());您目前正在打印FilterBypass对象。您需要通过传递偏移量和文档的长度来获取文档和文本。
https://stackoverflow.com/questions/23186316
复制相似问题