Java: Have a JTable’s column preferred width adjusted perfectly to the size of the longest string in the model

Here’s a utility method I’ve coded for FrostWire’s partial download dialog. With it I’m able to adjust a JTable’s column by iterating over the table’s column model data and calculating the exact dimensions required to render the longest string found. You can specify a maximum width (to avoid some really long strings from screwing up […]