When I combine HTML tags into JLabel text, I lose the ellipsis behavior that appears when the space is too small to display the full text. In my particular case, this is a TableCellRenderer that extends JLabel (default swing or other). Now that the column width is too small for the text to be shown fully, it does not show ellipses.
See the image below, for example: For the left column, I wrapped the text in the HTML renderer: setText("<html>" + "<strong>" + value.toString() + "</strong>" + "</html>"); . As you can see, when the column width is too small to contain text, it just gets cut. However, the right column showing the date and time and using DefaultTableCellRenderer shows the ellipsis when it does not contain the full text.

So my question is: can I have both? Sense, wrapping text with HTML and getting an ellipse?
UPDATE:
I found a reason not to get an ellipsis when using HTML. I followed the code from JComponent#paintComponent(Graphics g) up to BasicLabelUI#layoutCL(...) . See the following code snippet taken from the latter. This is only trimming the line if it does not have the html property (this is true when the label text is wrapped in html). But I have no idea how to get around this:
v = (c != null) ? (View) c.getClientProperty("html") : null; if (v != null) { textR.width = Math.min(availTextWidth, (int) v.getPreferredSpan(View.X_AXIS)); textR.height = (int) v.getPreferredSpan(View.Y_AXIS); } else { textR.width = SwingUtilities2.stringWidth(c, fm, text); lsb = SwingUtilities2.getLeftSideBearing(c, fm, text); if (lsb < 0) {
source share