static void setupColumnWidths()

in src/main/java/org/apache/sling/reqanalyzer/impl/gui/Util.java [87:110]


    static void setupColumnWidths(final TableColumnModel tcm, final String propertyName) {
        PropertyChangeListener pcl = new PropertyChangeListener() {
            private final String pclPropName = propertyName;
            private final TableColumnModel pclTcm = tcm;

            public void propertyChange(PropertyChangeEvent evt) {
                if ("width".equals(evt.getPropertyName())) {
                    int[] colWidths = new int[pclTcm.getColumnCount()];
                    for (int i = 0; i < colWidths.length; i++) {
                        colWidths[i] = pclTcm.getColumn(i).getWidth();
                    }
                    setPreference(pclPropName, colWidths, true);
                }
            }
        };

        int[] colWidths = getPreference(propertyName, new int[0]);
        for (int i = 0; i < colWidths.length && i < tcm.getColumnCount(); i++) {
            tcm.getColumn(i).setPreferredWidth(colWidths[i]);
        }
        for (int i = 0; i < tcm.getColumnCount(); i++) {
            tcm.getColumn(i).addPropertyChangeListener(pcl);
        }
    }