Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to enable all the text fields at once in Java Swing?

I have multiple text fields which I need to enabled or disabled at once using Java Swing. Is that possible?

like image 753
user1744099 Avatar asked Nov 24 '25 02:11

user1744099


2 Answers

If all the JTextFields are on a single container, you could do :

for (Component c : container.getComponents()) {
   if (c instanceof JTextField) {
      c.setEnabled(false);
   }
}
like image 114
Reimeus Avatar answered Nov 25 '25 14:11

Reimeus


if you put them all in a linked list / array list you could have a method to loop though it and enable / disable. This is probably the easiest way

like image 45
exussum Avatar answered Nov 25 '25 15:11

exussum