Hi all! I was wondering about how to clean multiple JTextField in a Java applicatio, without setting the text with an empty string for each field. Any suggestions?
A:
Track all the instances in an array? Swing does not majically know what's a JTextField and whats not.
And to my knowledge, setting the text to an empty string is the only way to clear text. T
TheLQ
2010-06-08 19:46:15
A `Collection<>`. Actually, go straight for a model in Swing - `Collection<Document>`.
Tom Hawtin - tackline
2010-06-08 19:55:06
+1
A:
Why would you want to do it differently? I guess you could do it by getDocument().remove(0, length)
or by setting a fresh document model, but both alternatives are worse than .setText("")
If you want some "global" clear-button (similar to an HTML <input type=reset />) the answer is that it's not possible in Java. You have to store the components in a collection somehow, and loop them through and clear each component one by one.
aioobe
2010-06-08 19:46:34