diff options
Diffstat (limited to 'libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java')
-rw-r--r-- | libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java index ef491cbf1c6..d3abba217cd 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java @@ -78,6 +78,7 @@ import javax.swing.plaf.InputMapUIResource; import javax.swing.plaf.TableUI; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; @@ -228,8 +229,6 @@ public class BasicTableUI extends TableUI if (e.getClickCount() < ce.getClickCountToStart()) return; } - else if (e.getClickCount() < 2) - return; table.editCellAt(row, col); } } @@ -387,10 +386,8 @@ public class BasicTableUI extends TableUI int maxTotalColumnWidth = 0; for (int i = 0; i < table.getColumnCount(); i++) maxTotalColumnWidth += table.getColumnModel().getColumn(i).getMaxWidth(); - if (maxTotalColumnWidth == 0 || table.getRowCount() == 0) - return null; - return new Dimension(maxTotalColumnWidth, table.getRowCount()* - (table.getRowHeight()+table.getRowMargin())); + + return new Dimension(maxTotalColumnWidth, getHeight()); } /** @@ -408,16 +405,45 @@ public class BasicTableUI extends TableUI int minTotalColumnWidth = 0; for (int i = 0; i < table.getColumnCount(); i++) minTotalColumnWidth += table.getColumnModel().getColumn(i).getMinWidth(); - if (minTotalColumnWidth == 0 || table.getRowCount() == 0) - return null; - return new Dimension(minTotalColumnWidth, table.getRowCount()*table.getRowHeight()); + + return new Dimension(minTotalColumnWidth, getHeight()); } + /** + * Returns the preferred size for the table of that UI. + * + * @param comp ignored, the <code>table</code> field is used instead + * + * @return the preferred size for the table of that UI + */ public Dimension getPreferredSize(JComponent comp) { - int width = table.getColumnModel().getTotalColumnWidth(); - int height = table.getRowCount() * (table.getRowHeight()+table.getRowMargin()); - return new Dimension(width, height); + int prefTotalColumnWidth = 0; + for (int i = 0; i < table.getColumnCount(); i++) + { + TableColumn col = table.getColumnModel().getColumn(i); + prefTotalColumnWidth += col.getPreferredWidth(); + } + return new Dimension(prefTotalColumnWidth, getHeight()); + } + + /** + * Returns the table height. This helper method is used by + * {@link #getMinimumSize(JComponent)}, {@link #getPreferredSize(JComponent)} + * and {@link #getMaximumSize(JComponent)} to determine the table height. + * + * @return the table height + */ + private int getHeight() + { + int height = 0; + int rowCount = table.getRowCount(); + if (rowCount > 0 && table.getColumnCount() > 0) + { + Rectangle r = table.getCellRect(rowCount - 1, 0, true); + height = r.y + r.height; + } + return height; } protected void installDefaults() @@ -428,7 +454,6 @@ public class BasicTableUI extends TableUI table.setSelectionForeground(UIManager.getColor("Table.selectionForeground")); table.setSelectionBackground(UIManager.getColor("Table.selectionBackground")); table.setOpaque(true); - rendererPane = new CellRendererPane(); } protected void installKeyboardActions() @@ -1188,6 +1213,9 @@ public class BasicTableUI extends TableUI public void installUI(JComponent comp) { table = (JTable)comp; + rendererPane = new CellRendererPane(); + table.add(rendererPane); + installDefaults(); installKeyboardActions(); installListeners(); @@ -1197,7 +1225,11 @@ public class BasicTableUI extends TableUI { uninstallListeners(); uninstallKeyboardActions(); - uninstallDefaults(); + uninstallDefaults(); + + table.remove(rendererPane); + rendererPane = null; + table = null; } /** @@ -1257,7 +1289,6 @@ public class BasicTableUI extends TableUI } Rectangle bounds = table.getCellRect(r0, c0, false); - // The left boundary of the area being repainted. int left = bounds.x; @@ -1278,9 +1309,9 @@ public class BasicTableUI extends TableUI bounds.x += widths[c] + columnMargin; } bounds.x = left; - bounds.y += table.getRowHeight(r) + rowMargin; + bounds.y += table.getRowHeight(r); // Update row height for tables with custom heights. - bounds.height = table.getRowHeight(r + 1); + bounds.height = table.getRowHeight(r + 1) - rowMargin; } bottom = bounds.y - rowMargin; @@ -1311,7 +1342,7 @@ public class BasicTableUI extends TableUI { // The horizontal grid is draw below the cells, so we // add before drawing. - y += table.getRowHeight(r) + rowMargin; + y += table.getRowHeight(r); gfx.drawLine(left, y, p2.x, y); } gfx.setColor(save); |