Local variable needs to be declared final-Collection of common programming errors
I’m receiving the error “local variable box is accessed from within inner class; needs to be declared final”. That seems alright, but I don’t really think it’s the best solution, so I was hoping maybe someone else can help me out. Here is my code:
public void showPublisherBox(JComboBox box) {
if (publisherBox == null) {
publisherBox = new AddPublisherForm();
publisherBox.setLocationRelativeTo(this);
}
publisherBox.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
this.populatePublishers(box);
}
private void populatePublishers(JComboBox box){
box.setModel(db.getPublishers());
}
});
publisherBox.setVisible(true);
}
Publisher form is just a new JFrame that opens up and takes in some information, and when it’s closed I want the JComboBox to be repopulated via setting the model from my db.getPublishers() method.
So is there a better way to do what I’m doing here, or am I going to have to declare something as final?
Thanks