I have a JTable and I am trying to add a header tool tip that will display the string that is in the table header for each of the header cells. I can set the value of the header cell:
colModel.getColumn(currentColumn).setHeaderValue(time + "(s)");
where colModel:
TableColumnModel colModel = audioTable.getColumnModel();
To do this, I've added this listener:
audioTable = new JTable(modelAudio);
JTableHeader header = audioTable.getTableHeader();
header.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseMoved(MouseEvent e) {
System.out.println("mouseMoved");
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(MouseEvent e) {
System.out.println("mouseDragged");
// TODO Auto-generated method stub
}
});
And I see mouseMoved
being printed over and over again in between this NPE:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthTableHeaderUI$HeaderRenderer.getTableCellRendererComponent(Unknown Source)
at javax.swing.table.JTableHeader.getToolTipText(Unknown Source)
at javax.swing.ToolTipManager$insideTimerAction.actionPerformed(Unknown Source)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I'm not sure how to get a longer stack trace, this is how I created the table:
modelAudio = new DefaultTableModel();
modelAudio.addColumn(" ");
audioTable = new JTable(modelAudio);
The tricky thing i am trying to do is to add column's dynamically, so i add a column each time the user populates the current column like so:
TableColumn tc = new TableColumn(modelAudio.getColumnCount());
tc.setHeaderValue(" ");
audioTable.addColumn(tc);
modelAudio.addColumn(tc);
Is the way that I am adding the columns the problem causing this NPE?