Document Filtering Question
- From: Chris <chrisliapis@xxxxxxxxx>
- Date: Wed, 28 May 2008 18:29:45 -0700 (PDT)
All,
I am missing something with regard to document filtering. I have
successfully built this app where the text clears (actually gets
replaced with "") everytime a keystoke is entered into my textField.
However, before the replacement with ("") I would like to somehow save
the text that is coming in to the textField (in a String variable
perhaps?).
Anyhow, your expertise would be very much appreciated.
Thank you,
Chris
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;
public class textAreaExample {
public static void main(String[] args) {
clear();
}
public static void clear() {
final JTextField field = new JTextField(30);
((AbstractDocument) (field.getDocument())).setDocumentFilter(new
DocumentFilter()
{
public void replace(FilterBypass fb, int offset, int length,
String string, AttributeSet attr)
throws BadLocationException {
fb.replace(offset, length, "", attr);
}
});
JFrame frame = new JFrame("ALiiS");
frame.getContentPane().add(field);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
.
- Follow-Ups:
- Re: Document Filtering Question
- From: Knute Johnson
- Re: Document Filtering Question
- Prev by Date: Re: JFrame resizing
- Next by Date: Re: Document Filtering Question
- Previous by thread: JFrame resizing
- Next by thread: Re: Document Filtering Question
- Index(es):
Relevant Pages
|