The answer to your IT questions
 

Advanced search  • Search tips
My QUESTIONS & ANSWERS
 Question:

I want to display html tooltip for cell in JTable

User Asked by: friending
Published on: 10:39/02.01.2008
Status: OPEN
Is it possible to display html tooltip from cell in JTable? What should I implement to achieve this.
 Answers: 1
Sort by: /\ date | rating
Image Answer by: xpert
Posted on: 10:39/02.01.2008
Rating: 1.8 from possible 5 with 9 votes
In JTable there is method:

public String getToolTipText(MouseEvent event) {
...
}

which uses tooltip from your renderer component. You can implement getToolTipText for your renderer component:

public String getToolTipText(MouseEvent event) {
 //your implementation goes here
}


If you use DefaultTableCellRenderer you can just set the tooltip directly in the method getTableCellRendererComponent:

public Component getTableCellRendererComponent(JTable table, Object value,
                          boolean isSelected, boolean hasFocus, int row, int column) {
    setToolTipText("<html>Tooltip at <b>cell</b> " + row + ", " + column + "</html>");
    return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

}


In order tooltip to be rendered as html you should include <html> in the beginning and </html> at the end of tooltip but you can use only very limited features of HTML in the tooltip.
Vote:

Please vote! Your opinion matters!
If you haven't found what you've looking for, post a question
  
| Home | Hall of fame | Register | Log in | Terms of service | Help | Contacts |