This is a continuation of the "JTable and ToolTips per Cell" thread from 
January 4, 2001.

To summarize, to add tooltips to a JTable, extend the CellRenderer, eg:

   jtable = new JTable();
   jtable.setDefaultRenderer(Object.class, new MyTableCellRenderer() );
   ToolTipManager.sharedInstance().registerComponent(jtable);

   private class MyTableCellRenderer extends 
javax.swing.table.DefaultTableCellRenderer {

     public Component getTableCellRendererComponent( JTable table, 
Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {

       Component c = super.getTableCellRendererComponent( table, value, 
isSelected,
        hasFocus, row, column);

       if (value instanceof NamedObject) {
 
((JComponent)c).setToolTipText(((NamedObject)value).getDescription());
       }
       // LOOK!! should turn tip off if there is none !!

       return c;
     }
   }

So this works fine except that the placement of the tooltip is wrong 
when the JTable is on the left edge of the screen, in which case long 
tooltips get their left part chopped off. For some reason the 
ToolTipManager doesnt do its normal job of placing tooltips correctly 
near the window edge.

Now if I add a getToolTipLocation() method to MyTableCellRenderer, it 
never gets called. When I add getToolTipLocation() method to the JTree, 
the tooltip blinks like crazy like its in some loop, then sometimes 
finally displays the tooltip, but in the same location as before.

     // add tooltips
   private class MyJTable extends javax.swing.JTable {

     public Point getToolTipLocation(MouseEvent e) {
       return e.getPoint();
     }
   }

If getToolTipLocation() returns null, then I get the previous behavior 
of chopping off the edge of the screen.

This is all in JDK 1.3. Anyone have any ideas on why the tooltip 
location is unusual?

thanks,
John Caron

_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to