I have a class that extends JPanel. In its constructor I'm passing this
to other methods, mainly to add the jpanel object as a listener to containers/controls within the jpanel (but also other objects). Since Netbeans shows a leaking this in constructor
warning for those calls I've put them in an other method that is called from the constructor.
before:
class Foo ... {
public Foo() {
initComponents();
tabX.addChangeListener(this); // <- netbeans complains here
}
after:
class Foo ... {
public Foo() {
initComponents();
initListeners();
}
protected void initListeners() {
tabX.addChangeListener(this);
}
That gets rid of the symptom. But I doubt it fixes the reason why netbeans shows the warning.
Where is the proper place to do this kind of initialization in a JPanel-derived class?