Search code examples
javaswingjtabletablecellrenderer

TableCellRenderer with too small column has no dots suffix


I try to learn the JTables TableCellRenderer and there is something I don't understand. Maybe one of you can help me.

Please have a look on this example I found on the Web: http://www.java2s.com/Tutorial/Java/0240__Swing/implementsTableCellRenderer.htm

It is a simple compilable unit to demonstrate the use of a TableCellRenderer.

But now, with a defined Renderer, when I shrink the columns the titles are still trunk and get a ending "...". The values are only "hidden", because there is not enough space. The "..." are missing. Please see the image .

enter image description here

Is there a possibility to get the "..." for the value cells?


Solution

  • as others commented, your cell renderer returns a JTextField. in swing, this clip string implementation is there in the class called SwingUtilities2.

    public static String clipString(JComponent var0, FontMetrics var1, String var2, int var3)
    

    But this clip string logic will be used by some components only. ex: Button, RadioButton, TabPane, MenuItem, Label.