I don't know how to get my tooltips to work

132 Views Asked by At

So I read a few threads that had tool tips working and tried to work off that to no avail.

import java.awt.event.MouseEvent;

public String getToolTipText(MouseEvent e) {
    String tip = "tommy likes trucks";
    java.awt.Point p = e.getPoint();
    int rowIndex = FursJTable.rowAtPoint(p);
    int colIndex = FursJTable.columnAtPoint(p);
    int realColumnIndex = FursJTable.convertColumnIndexToModel(colIndex);
    //if (description[realColumnIndex] = null || description[realColumnIndex] = "") {
    //    tip = null;
    //} else {
    //    tip = description[realColumnIndex];
    //}
    return tip;
}

The if statement should just pull a string from an array I will have set up but even if I just set the tip at the beginning of the code it doesn't show a tooltip anywhere in my jtable. All help is appreciated. :)

I also need the tooltip to be across the entire row. but this still doesn't matter yet because i can't get the tooltip to appear anywhere.

1

There are 1 best solutions below

4
On
int rowIndex = FursJTable.rowAtPoint(p);
int colIndex = FursJTable.columnAtPoint(p);
int realColumnIndex = FursJTable.convertColumnIndexToModel(colIndex);

The getToolTipText(...) method is part of the JTable. Since you are overriding the code in JTable there is no need for you to refer to an instance variable. Just use:

int rowIndex = rowAtPoint(p);
int colIndex = columnAtPoint(p);
int realColumnIndex = convertColumnIndexToModel(colIndex);

Also, follow Java naming conventions. Variable names should NOT start with an upper case character.

If you need more help then post a proper SSCCE that demonstrates the problem.

Edit:

One way to extend a component to override a single method is to do something like:

JTable table = new JTable( ... )
{
    public String getToolTipText( MouseEvent e )
    {
        return "hello";
    }
};