JDK-6447706 : investigate using delegates instead of creating new listeners for swing classes
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2006-07-11
  • Updated: 2011-02-09
  • Resolved: 2011-02-09
Related Reports
Relates :  
Description
In many cases our code creates new listener classes. Given that class is expensive asset we might want to reduce the number of classes we have. Some times it could be avoided by creating one listner which implements multiple listener interfaces. In addition to that that listener can delegate event handling to the class methods to let subclasses to take advantage of it.

For example WindowsComboBoxUI has two listener classes. One for property change events and another one for mouse events. If BasicComboBox would have methods to listen for those events that would help to avoid creating two new classes.

My concern is it would harm readability and maintainability of the code because different concerns will be mixed in one class.
The counter argument to that is it will help to avoid some programming mistakes because one would not need to worry about registering/unregistering the listeners for it all will be taken care of.

There is java.beans.EventHandler which can help to reduce the number of listener classes. I am a bit skeptical of using it intrenally in swing though.

Comments
EVALUATION We are not going to fix it this way
09-02-2011