Changeset 5784 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2013-03-19T11:59:21+01:00 (12 years ago)
Author:
akks
Message:

Auto adjust column width in remote control add_tags table.
(noticed by CupIvan) Method TableHelper.adjustColumnWidth(table, column, maxColumnWidth) can also be used in any other place of code

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r5763 r5784  
    8383import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    8484import org.openstreetmap.josm.gui.util.FileFilterAllFiles;
     85import org.openstreetmap.josm.gui.util.TableHelper;
    8586import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
    8687import org.openstreetmap.josm.io.MirroredInputStream;
     
    154155            @Override
    155156            public void tableChanged(TableModelEvent e) {
    156                 adjustColumnWidth(tblActiveSources, isMapPaint ? 1 : 0);
     157                TableHelper.adjustColumnWidth(tblActiveSources, isMapPaint ? 1 : 0, 800);
    157158            }
    158159        });
     
    387388        LOADING_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM_HELP_TOPIC,
    388389        ILLEGAL_FORMAT_OF_ENTRY }
    389 
    390     /**
    391      * adjust the preferred width of column col to the maximum preferred width of the cells
    392      * requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    393      */
    394     private static void adjustColumnWidth(JTable tbl, int col) {
    395         int maxwidth = 0;
    396         for (int row=0; row<tbl.getRowCount(); row++) {
    397             TableCellRenderer tcr = tbl.getCellRenderer(row, col);
    398             Object val = tbl.getValueAt(row, col);
    399             Component comp = tcr.getTableCellRendererComponent(tbl, val, false, false, row, col);
    400             maxwidth = Math.max(comp.getPreferredSize().width, maxwidth);
    401         }
    402         tbl.getColumnModel().getColumn(col).setPreferredWidth(maxwidth);
    403     }
    404390
    405391    public boolean hasActiveSourcesChanged() {
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java

    r5707 r5784  
    2727import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2828import org.openstreetmap.josm.gui.ExtendedDialog;
     29import org.openstreetmap.josm.gui.util.TableHelper;
    2930import org.openstreetmap.josm.tools.GBC;
    3031
     
    110111        };
    111112       
     113        propertyTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    112114        // a checkbox has a size of 15 px
    113115        propertyTable.getColumnModel().getColumn(0).setMaxWidth(15);
     116        TableHelper.adjustColumnWidth(propertyTable, 1, 200);
     117        TableHelper.adjustColumnWidth(propertyTable, 2, 700);
    114118        // get edit results if the table looses the focus, for example if a user clicks "add tags"
    115119        propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
     
    128132        setContent(tablePanel);
    129133        setDefaultButton(2);
    130         // set the default Dimensions and show the dialog
    131         setPreferredSize(new Dimension(400,tablePanel.getPreferredSize().height+100));
    132134    }
    133135
Note: See TracChangeset for help on using the changeset viewer.