Changeset 14476 in josm


Ignore:
Timestamp:
2018-12-01T15:58:46+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #14666 - Autoresize Tags/Memberships table to fit content (patch by bagage)

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r14470 r14476  
    9696import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
    9797import org.openstreetmap.josm.gui.util.HighlightHelper;
     98import org.openstreetmap.josm.gui.util.TableHelper;
    9899import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator;
    99100import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
     
    309310        tagData.setColumnIdentifiers(new String[]{tr("Key"), tr("Value")});
    310311        tagTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     312        tagTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    311313        tagTable.getTableHeader().setReorderingAllowed(false);
    312314
     
    333335        membershipData.setColumnIdentifiers(new String[]{tr("Member Of"), tr("Role"), tr("Position")});
    334336        membershipTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     337        membershipTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    335338
    336339        TableColumnModel mod = membershipTable.getColumnModel();
     
    670673        pluginHook.setVisible(hasSelection);
    671674
     675        // resize tables to fit content
     676        TableHelper.computeColumnsWidth(tagTable);
     677        TableHelper.computeColumnsWidth(membershipTable);
     678
    672679        int selectedIndex;
    673680        if (selectedTag != null && (selectedIndex = findViewRow(tagTable, tagData, selectedTag)) != -1) {
  • trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java

    r9231 r14476  
    1717
    1818    /**
    19      * (originally from @class org.openstreetmap.josm.gui.preferences.SourceEditor)
    2019     * adjust the preferred width of column col to the maximum preferred width of the cells
    2120     * requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     
    3433        tbl.getColumnModel().getColumn(col).setPreferredWidth(Math.min(maxwidth+10, maxColumnWidth));
    3534    }
     35
     36    /**
     37     * adjust the table's columns to fit their content best
     38     * requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     39     * @param tbl table
     40     * @since 14476
     41     */
     42    public static void computeColumnsWidth(JTable tbl) {
     43        for (int column = 0; column < tbl.getColumnCount(); column++) {
     44            adjustColumnWidth(tbl, column, Integer.MAX_VALUE);
     45        }
     46    }
    3647}
Note: See TracChangeset for help on using the changeset viewer.