title: How do I add a Tool Tip generated from the Table Header to my JTable cells?
body: <p>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:</p>
  
  <p><code>colModel.getColumn(currentColumn).setHeaderValue(time + "(s)");</code></p>
  
  <p>where colModel:</p>
  
  <pre><code>TableColumnModel colModel = audioTable.getColumnModel();
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kLgO1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kLgO1.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/sh8UF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sh8UF.png" alt="enter image description here"></a></p>
  
  <p>To do this, I've added this listener:</p>
  
  <pre><code>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
  
          }
      });
  </code></pre>
  
  <p>And I see <code>mouseMoved</code> being printed over and over again in between this NPE:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I'm not sure how to get a longer stack trace, this is how I created the table:</p>
  
  <pre><code>modelAudio = new DefaultTableModel();
  modelAudio.addColumn(" ");
  audioTable = new JTable(modelAudio);
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>TableColumn tc = new TableColumn(modelAudio.getColumnCount());
  tc.setHeaderValue(" ");
  audioTable.addColumn(tc);
  modelAudio.addColumn(tc);
  </code></pre>
  
  <p>Is the way that I am adding the columns the problem causing this NPE?</p>