Java Tips Weblog

  • Blog Stats

    • 1,556,429 hits
  • Categories

  • Archives

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();

… and the table would display like:


Get The Code

See Also

Table Column Adjuster

Related Reading

Concepts: Editors and Renderers

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 105 other followers

%d bloggers like this: