From 2c15882d0dca7f712adec4dc9c118d0dd88fa4e8 Mon Sep 17 00:00:00 2001
From: Gautier Pelloux-Prayer <gautier+git@damsy.net>
Date: Mon, 12 Nov 2018 21:29:01 +0100
Subject: [PATCH] Automatically recompute tags and membership tables' columns
 width to fit content

---
 .../dialogs/properties/PropertiesDialog.java    | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
index 1b1d9c4ab..23b7e8056 100644
--- a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
+++ b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
@@ -303,6 +303,19 @@ implements DataSelectionListener, ActiveLayerChangeListener, DataSetListenerAdap
         return HelpUtil.ht("/Dialog/TagsMembership");
     }
 
+    private void computeColumnsWidth(JTable table) {
+        final TableColumnModel columnModel = table.getColumnModel();
+        for (int column = 0; column < table.getColumnCount(); column++) {
+            int width = 15; // Min width
+            for (int row = 0; row < table.getRowCount(); row++) {
+                TableCellRenderer renderer = table.getCellRenderer(row, column);
+                Component comp = table.prepareRenderer(renderer, row, column);
+                width = Math.max(comp.getPreferredSize().width +1 , width);
+            }
+            columnModel.getColumn(column).setPreferredWidth(width);
+        }
+    }
+
     private void buildTagsTable() {
         // setting up the tags table
         tagData.setColumnIdentifiers(new String[]{tr("Key"), tr("Value")});
@@ -667,6 +680,10 @@ implements DataSelectionListener, ActiveLayerChangeListener, DataSetListenerAdap
         selectSth.setVisible(!hasSelection);
         pluginHook.setVisible(hasSelection);
 
+        // resize tables to fit content
+        computeColumnsWidth(tagTable);
+        computeColumnsWidth(membershipTable);
+
         int selectedIndex;
         if (selectedTag != null && (selectedIndex = findViewRow(tagTable, tagData, selectedTag)) != -1) {
             tagTable.changeSelection(selectedIndex, 0, false, false);
-- 
2.19.1

