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?
I was wondering about how to clean multiple JTextField in a Java applicatio, without
Share
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.