Skip to content

Conversation

@fjebaker
Copy link

@fjebaker fjebaker commented Feb 3, 2026

As mentioned per email.

As far as I can tell, this should be relatively harmless. I've had a few problems where the drawing sometimes entirely fails (very not good) because the LabelUI draw call is "fired" before the window is ready, and so the FontMetrics are not initialised -- at least that's what I infer from trying to attach the Java debugger? As a consequence, there is an otherwise seemingly unneccessary check to see if FontMetrics is null. Since then, it's run very smoothly, but I would still recommend abusing this in any way you can to be on the safe side.

There is another way this could be done by implementing a custom TableCellRenderer, but that leads to some complications, because the (pixel) width of the column is not easily known, nor is how the font will render the text -- so you'd either end up with a large whitespace gap at the end of the string in the cell, or the string would be cut off by the end of the column.

When a cell in a JTable is truncated, the last few characters are cut
off and an ellipsis is inserted at the end. Often the most important
bits of information are at the beginning and the end of the string, as
e.g.  the file extensions or table names in a DataLink URL are present
only at the end of the string. An extreme example:

    topcat/src/main/uk/ac/st...
    topcat/src/main/uk/ac/st...

This adds a custom LabelUI which modifies how all labels in Swing are
drawn, so that if an ellipsis is inserted, it is put in the middle of
the string instead of at the end. The above becomes:

    topcat/src/m...striver.java
    topcat/src/m...atModel.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant