Is this your first time here? SwingWiki is a Java Swing Developer community site with an big archive of Swing-related usenet groups and mailing lists, but also tips, tricks and articles and book reviews written by your colleagues from around the world. If you came here through a search engine and did not find what you were looking for, make sure to check the wiki table of contents.

Individual tool tips for table cells

Entire JTable has a single tool tip text. It can be useful to change the tool tip text for certain cells, and even to show the entire cell content inside the tool tip (this is one of the best solutions for tables with a long cell content - see also Multi-line Cells).

To do this, you must subclass JTable, and override getToolTipText(). Use getColumnAtPoint and getRowAtPoint to find the cell below mouse pointer. If you expect the content to be long, be sure to wrap it into a HTML document with constrained width (see also Use HTML Content).

public class HintTable extends JTable {   	
    		public String getToolTipText(MouseEvent event){
        	Point p=event.getPoint();
	        	int col=columnAtPoint(p);
        	int rw=rowAtPoint(p);
        	if (col>=0 && rw>=0) {
            		Object o=getValueAt(rw,col);
   	      		if (o!=null) return "<html><body style=\"width:250px\"><p>"+o.toString()+"</p></body></html>";
        	return "";

Comments? Corrections? Contact us or Login to edit pages directly (registration is free and takes less than displaying a JLabel)
  howto/table_cell_tool_tip.txt · Last modified: 2005/02/14 18:04 by (gojko)
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++| Ruby Resources

Sedo - Buy and Sell Domain Names and Websites project info: Statistics for project etracker� web controlling instead of log file analysis