Search code examples
netbeansaddeventlistenerjavabeansbeaninfo

Java - Add custom event Listener to a eventSet in beanInfo with Netbeans


i have a custom bean and a custom eventListener, i need to show my event Listener in the events tab of my bean.

I think the solution is to add my event Listener to a beaninfo(i create it with netbeans, so it is auto-generated). There is a "wizard-way" to do this, or i have to hand-write my beaninfo?

Thanks.


Solution

  • The solution is to have all methods for listener management, so Netbeans can recognize it and put it inside beaninfo.

    For example, if you have a custom listener called ActionDataListener, you have to add this methods:

        public void addActionDataListener(ActionDataListener listener) {
            actionDataListeners.add(listener);
        }
    
        public void removeActionDataListener(ActionDataListener listener) {
            actionDataListeners.remove(listener);
        }
    
        public ActionDataListener[] getActionDataListeners() {
            return actionDataListeners.toArray(new ActionDataListener[0]);
        }