iamprogrammer
iamprogrammer

Reputation: 27

ToolTipText on Jtable

How to create a tool tip text in a specific column on JTable.

This is what I have come up to.

itemTable = new JTable(model){
            if (c instanceof JComponent) {
                if(columns == 7){
                    JComponent jc = (JComponent) c;
                    jc.setToolTipText("Price per item");
                }
            }
            return c;
        }
    };

Sad to say this is not working.

Upvotes: 1

Views: 204

Answers (1)

camickr
camickr

Reputation: 324118

Usually the tool tip would be added to the header of the table.

One way to do this is to override the getToolTipText(...) method of the JTableHeader.

Read the section from the Swing tutorial on Specifying Tool Tips for Table Headers for a working example.

The same concept can be applied for the JTable as well.

The tutorial also shows how you could use a custom renderer to set the tool tip text.

Upvotes: 3

Related Questions