Originally Posted by
GregBrannon
Does the table display before the refresh? The table is a component, the table model is a behind the scenes description of the table, so the first step is to reliably display the component. Can you do the first step?
Here is my TablePanel.java:
package gui;
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import model.Person;
public class TablePanel extends JPanel {
private static final long serialVersionUID = -5068640091114058027L;
private JTable table;
private PersonTableModel tableModel;
public TablePanel() {
tableModel = new PersonTableModel();
table = new JTable(tableModel);
setLayout(new BorderLayout());
add(new JScrollPane(table), BorderLayout.CENTER);
}
public void setData(List<Person> db) {
tableModel.setData(db);
}
public void refresh() {
tableModel.fireTableDataChanged();
}
}
This is starting to drive me insane, I can't figure this shit out. When I add an element and use refresh it works just fine. I don't know if it's just not displaying or if it's not loading anything at all.
--- Update ---
Originally Posted by
GregBrannon
Does the table display before the refresh? The table is a component, the table model is a behind the scenes description of the table, so the first step is to reliably display the component. Can you do the first step?
The table column names display but no data.
--- Update ---
Solved! This was a response from John Purcell of caveofprogramming.com:
You're doing this in MainFrame.java: final Controller controller = new Controller();
So you're creating a new controller, creating a new variable at local scope overshadowing the one at class scope that you actually need to be using. What you need is this: controller = new Controller();
The controller that you then try to use is the instance variable, which was not set to new anything.
Then to fix the null pointer, you added more new controller statements, creating new databases all over the place
I think every programmer has made this mistake sometime -- declaring a new local variable by mistake, instead of initializing the class-level one. You have to pay careful attention to what those null pointer exceptions tell you --- otherwise they extract dire payment. They are usually easy to fix once you know how.