Changeset 15176 in josm for trunk/src/org
- Timestamp:
- 2019-06-16T23:25:10+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/FilterDialog.java
r14932 r15176 48 48 import org.openstreetmap.josm.gui.util.MultikeyActionsHandler; 49 49 import org.openstreetmap.josm.gui.util.MultikeyShortcutAction; 50 import org.openstreetmap.josm.gui.util.TableHelper; 50 51 import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField; 51 52 import org.openstreetmap.josm.tools.ImageProvider; … … 119 120 userTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 120 121 userTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 121 122 userTable.getColumnModel().getColumn(0).setMaxWidth(1); 123 userTable.getColumnModel().getColumn(1).setMaxWidth(1); 124 userTable.getColumnModel().getColumn(3).setMaxWidth(1); 125 userTable.getColumnModel().getColumn(4).setMaxWidth(1); 126 127 userTable.getColumnModel().getColumn(0).setResizable(false); 128 userTable.getColumnModel().getColumn(1).setResizable(false); 129 userTable.getColumnModel().getColumn(3).setResizable(false); 130 userTable.getColumnModel().getColumn(4).setResizable(false); 122 userTable.setAutoCreateRowSorter(true); 123 124 TableHelper.adjustColumnWidth(userTable, 0, false); 125 TableHelper.adjustColumnWidth(userTable, 1, false); 126 TableHelper.adjustColumnWidth(userTable, 3, false); 127 TableHelper.adjustColumnWidth(userTable, 4, false); 131 128 132 129 userTable.setDefaultRenderer(Boolean.class, new BooleanRenderer()); -
trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java
r14476 r15176 6 6 import javax.swing.JTable; 7 7 import javax.swing.table.TableCellRenderer; 8 import javax.swing.table.TableColumn; 8 9 9 10 /** 10 11 * The class that provide common JTable customization methods 12 * @since 5785 11 13 */ 12 14 public final class TableHelper { … … 16 18 } 17 19 20 static int getColumnHeaderWidth(JTable tbl, int col) { 21 TableColumn tableColumn = tbl.getColumnModel().getColumn(col); 22 TableCellRenderer renderer = tableColumn.getHeaderRenderer(); 23 24 if (renderer == null) { 25 renderer = tbl.getTableHeader().getDefaultRenderer(); 26 } 27 28 Component c = renderer.getTableCellRendererComponent(tbl, tableColumn.getHeaderValue(), false, false, -1, col); 29 return c.getPreferredSize().width; 30 } 31 32 static int getMaxWidth(JTable tbl, int col) { 33 int maxwidth = getColumnHeaderWidth(tbl, col); 34 for (int row = 0; row < tbl.getRowCount(); row++) { 35 TableCellRenderer tcr = tbl.getCellRenderer(row, col); 36 Object val = tbl.getValueAt(row, col); 37 Component comp = tcr.getTableCellRendererComponent(tbl, val, false, false, row, col); 38 maxwidth = Math.max(comp.getPreferredSize().width, maxwidth); 39 } 40 return maxwidth; 41 } 42 18 43 /** 19 * adjust the preferred width of column col to the maximum preferred width of the cells 44 * adjust the preferred width of column col to the maximum preferred width of the cells (including header) 45 * @param tbl table 46 * @param col column index 47 * @param resizable if true, resizing is allowed 48 * @since 15176 49 */ 50 public static void adjustColumnWidth(JTable tbl, int col, boolean resizable) { 51 int maxwidth = getMaxWidth(tbl, col); 52 TableColumn column = tbl.getColumnModel().getColumn(col); 53 column.setPreferredWidth(maxwidth); 54 column.setResizable(resizable); 55 if (!resizable) { 56 column.setMaxWidth(maxwidth); 57 } 58 } 59 60 /** 61 * adjust the preferred width of column col to the maximum preferred width of the cells (including header) 20 62 * requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 21 63 * @param tbl table … … 24 66 */ 25 67 public static void adjustColumnWidth(JTable tbl, int col, int maxColumnWidth) { 26 int maxwidth = 0; 27 for (int row = 0; row < tbl.getRowCount(); row++) { 28 TableCellRenderer tcr = tbl.getCellRenderer(row, col); 29 Object val = tbl.getValueAt(row, col); 30 Component comp = tcr.getTableCellRendererComponent(tbl, val, false, false, row, col); 31 maxwidth = Math.max(comp.getPreferredSize().width, maxwidth); 32 } 68 int maxwidth = getMaxWidth(tbl, col); 33 69 tbl.getColumnModel().getColumn(col).setPreferredWidth(Math.min(maxwidth+10, maxColumnWidth)); 34 70 }
Note:
See TracChangeset
for help on using the changeset viewer.