loop through JPanel

后端 未结 2 1771
旧巷少年郎
旧巷少年郎 2020-12-19 12:24

In order to initialize all JTextfFields on a JPanel when users click a \"clear button\", I need to loop through the JPanel (instead of

2条回答
  •  星月不相逢
    2020-12-19 13:02

    Whilst another answer shows a direct way to solve your problem, your question is implying a poor solution.

    Generally want static dependencies between layers to be one way. You should need to go a pack through getCommponents. Casting (assuming generics) is an easy way to see that something has gone wrong.

    So when you create the text fields for a form, add them to the list to be cleared in a clear operation as well as adding them to the panel. Of course in real code there probably other things you want to do to them too. In real code you probably want to be dealing with models (possibly Document) rather than JComponents.

提交回复
热议问题