Reputation: 2641
I am trying to get an outer class reference in a nested class. Basically, I have a class inside another, so when I try to use the keyword "this" it doesn't reference the parent.
public class A extends JPanel {
public A() {
...
options.add(new JMenuItem(new AbstractAction("item") {
public void actionPerformed(ActionEvent e) {
window.setOldPanel(this); // this is the ActionEvent, not what I want (the outer class reference)
}
}
)))
}
}
Is there any way to do this without creating an instance of the parent in the nested?
Thanks.
Upvotes: 0
Views: 37
Reputation: 198033
You're looking for A.this
, which properly refers to the A
this
.
Upvotes: 2