Left Dot Renderer
Posted by Rob Camick on November 12, 2008
The default renderer for a JTable uses a JLabel to provide the rendering. When the text on the label is truncated, the text is displayed left justified with trailing dots. There may be occasions when the trailing part of the text is more important than the start of the text and you would rather have the text right justified with leading dots. We can’t easily change the default behavour of a label, but we can change the behavour of the renderer.
Of course you could just increase the column width to see all the text and that is now easier thanks to the TableColumnAdjuster described in an earlier entry. However, this entry is about customizing the rendering. The LeftDotRenderer will display the text normally in the table column as long as the text fits in the width of the table column. When the text is too long to display completely, the renderer will determine the number of characters that can be displayed and then insert “…” at the start of the text to give the desired effect of right justifying the renderer.
To install the renderer of a given column you would use code like…
LeftDotRenderer leftDot = new LeftDotRenderer();
table.getColumnModel().getColumn(1).setCellRenderer(leftDot);
… and the table would display like:

Leave a comment