Issue
I have a JTable where one column occasionally has a fair amount of text in it. There are algorithms that we're using to expand the height of each row to the tallest cell. The problem is for long text cells we get "fat" rows.
============================= | Col1 | Col2 | This is some| | | | very long | | | | text! | =============================
I've considered a couple solutions:
- Clipping the text and adding a mouse listener to "expand" the clipped text
- Clipping the text and adding a tooltip or dialog to show the extra contents
Does anyone know of any libraries that fix this? I'm open to using some other technique...I'm not convinced my solution is the best.
Thanks in advance!
Solution
I would just use a tooltip.
You can override the getToolTipText(() method of JTable to do this.
JTable table = new JTable(...)
{
public String getToolTipText( MouseEvent e )
{
int row = rowAtPoint( e.getPoint() );
int column = columnAtPoint( e.getPoint() );
Object value = getValueAt(row, column);
return value == null ? null : value.toString();
}
};
Or if its only for certain columns you can use the renderer to set the tooltip text. See Specifying Tool Tips for Cells.
Answered By - camickr
Answer Checked By - David Marino (JavaFixing Volunteer)