Reset JComponent to default value

后端 未结 5 562
广开言路
广开言路 2021-01-21 16:58

For example, if component is a checkbox it must set to false, or it is a textfield it must be clear the text. I am trying to write a method for reset all components in a J

5条回答
  •  一向
    一向 (楼主)
    2021-01-21 17:12

    One possible workaround would be to create a custom reset function. Reinitialize the panel ( your form).

    For e.g.

    void reset(){
        //recreate the form panel.
        formPanel = new FormPanel(); 
    }
    

    Create a custom class FormPanel to store the form fields and their listeners.

    Re initializing the panel components would result in an overhead of reassigning the listeners as @Robin suggested.

提交回复
热议问题