tags:

views:

30

answers:

1

By default Swing uses ellipses "..." to indicate that text has been truncated in JLabel and similar text based components. Is it possible to change this behavior to use a different character string, for example ">"?

Looking through the Swing code I found in SwingUtilities2 a method called clipString(...) which appears to hardcode the string to be "...".

+1  A: 

I am not sure you can set that in Swing. Consider making your own JLabel implementation that truncates the string as you want it.

Here you could use the truncation functions from SwingUtilities. You could begin with copy pasting the code from it, that usually is a good start.

I think you need to extend the paintComponent method of the JLabel, measure the FontMetrics and determine if the label needs truncation. If it does set the text to the truncated value. Remember to keep the not-truncated value in a field or so.

Jes