source: josm/trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java@ 8041

Last change on this file since 8041 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.util;
3
4import java.awt.Component;
5
6import javax.swing.JTable;
7import javax.swing.table.TableCellRenderer;
8
9/**
10 * The class that provide common JTable customization methods
11 */
12public final class TableHelper {
13
14 private TableHelper() {
15 // Hide default constructor for utils classes
16 }
17
18 /**
19 * (originally from @class org.openstreetmap.josm.gui.preferences.SourceEditor)
20 * adjust the preferred width of column col to the maximum preferred width of the cells
21 * requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
22 */
23 public static void adjustColumnWidth(JTable tbl, int col, int maxColumnWidth) {
24 int maxwidth = 0;
25 for (int row=0; row<tbl.getRowCount(); row++) {
26 TableCellRenderer tcr = tbl.getCellRenderer(row, col);
27 Object val = tbl.getValueAt(row, col);
28 Component comp = tcr.getTableCellRendererComponent(tbl, val, false, false, row, col);
29 maxwidth = Math.max(comp.getPreferredSize().width, maxwidth);
30 }
31 tbl.getColumnModel().getColumn(col).setPreferredWidth(Math.min(maxwidth+10, maxColumnWidth));
32 }
33}
Note: See TracBrowser for help on using the repository browser.