Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / net / sf / openrocket / gui / util / GUIUtil.java
index 4ee74ba4e83edfc75245c9020ecaf00e26d9ba84..4ac68dcebcad4091b856f7d7a511fcb011d43b17 100644 (file)
@@ -348,6 +348,26 @@ public class GUIUtil {
        }
        
        
+       public static void setAutomaticColumnTableWidths(JTable table, int max) {
+               int columns = table.getColumnCount();
+               int widths[] = new int[columns];
+               Arrays.fill(widths, 1);
+               
+               for (int row = 0; row < table.getRowCount(); row++) {
+                       for (int col = 0; col < columns; col++) {
+                               Object value = table.getValueAt(row, col);
+                               //System.out.println("row=" + row + " col=" + col + " : " + value);
+                               widths[col] = Math.max(widths[col], value == null ? 0 : value.toString().length());
+                       }
+               }
+               
+               
+               for (int col = 0; col < columns; col++) {
+                       System.err.println("Setting column " + col + " to width " + widths[col]);
+                       table.getColumnModel().getColumn(col).setPreferredWidth(Math.min(widths[col], max) * 100);
+               }
+       }
+       
        /**
         * Changes the style of the font of the specified border.
         * 
@@ -362,10 +382,10 @@ public class GUIUtil {
                 */
                Font font = border.getTitleFont();
                if (font == null) {
-                       log.error("Border font is null, reverting to JLabel font");
+                       log.warn("JRE bug workaround : Border font is null, reverting to JLabel font");
                        font = new JLabel().getFont();
                        if (font == null) {
-                               log.error("JLabel font is null, not modifying font");
+                               log.warn("JRE bug workaround : JLabel font is null, not modifying font");
                                return;
                        }
                }