The attached patch fixes a couple of issues in JTables:
- the border color for selected cells was not correct in the Metal L&F
- the table was not painted correctly. The grid must be painted to the
right and bottom of each cell, we painted it to the top and left
- related to the previous, the cells have been mis-aligned

2006-05-04  Roman Kennke <[EMAIL PROTECTED]>

        * javax/swing/JTable.java
        (moveToCellBeingEdited): Adjust bounding box of editing
component
        to exactly cover the grid.
        * javax/swing/plaf/basic/BasicTableUI.java
        (paint): Paint grid to the bottom and right of the cells instead
        of left and top. Adjust bounding box of cells accordingly.
        * javax/swing/plaf/metal/MetalLookAndFeel.java
        (initComponentDefaults): Fixed color of JTable selection border.
        * javax/swing/plaf/metal/OceanTheme.java
        (addCustomEntriesToTable): Fixed color of JTable selection
border.

/Roman

Index: javax/swing/JTable.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.97
diff -u -1 -0 -r1.97 JTable.java
--- javax/swing/JTable.java	25 Apr 2006 09:13:28 -0000	1.97
+++ javax/swing/JTable.java	4 May 2006 12:10:54 -0000
@@ -3714,20 +3714,27 @@
 
   /**
    * Move the given component under the cell being edited. 
    * The table must be in the editing mode.
    * 
    * @param component the component to move.
    */
   private void moveToCellBeingEdited(Component component)
   {
      Rectangle r = getCellRect(editingRow, editingColumn, true);
+     // Adjust bounding box of the editing component, so that it lies
+     // 'above' the grid on all edges, not only right and bottom.
+     // The table grid is painted only at the right and bottom edge of a cell.
+     r.x -= 1;
+     r.y -= 1;
+     r.width += 1;
+     r.height += 1;
      component.setBounds(r);
   }
 
   /**
    * Programmatically starts editing the specified cell.
    *
    * @param row the row of the cell to edit.
    * @param column the column of the cell to edit.
    */
   public boolean editCellAt (int row, int column, EventObject e)
Index: javax/swing/plaf/basic/BasicTableUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTableUI.java,v
retrieving revision 1.49
diff -u -1 -0 -r1.49 BasicTableUI.java
--- javax/swing/plaf/basic/BasicTableUI.java	17 Apr 2006 07:41:05 -0000	1.49
+++ javax/swing/plaf/basic/BasicTableUI.java	4 May 2006 12:10:54 -0000
@@ -1238,79 +1238,83 @@
     int r0 = table.rowAtPoint(p1);
     if (r0 == -1)
       r0 = 0;
     Point p2 = new Point(clip.x + clip.width, clip.y + clip.height);
     int cn = table.columnAtPoint(p2);
     if (cn == -1)
       cn = table.getColumnCount() - 1;
     int rn = table.rowAtPoint(p2);
     if (rn == -1)
       rn = table.getRowCount() - 1;
-    
+
+    int columnMargin = table.getColumnModel().getColumnMargin();
+    int rowMargin = table.getRowMargin();
+
     TableColumnModel cmodel = table.getColumnModel();
     int [] widths = new int[cn+1];
     for (int i = c0; i <=cn ; i++)
       {
-        widths[i] = cmodel.getColumn(i).getWidth();
+        widths[i] = cmodel.getColumn(i).getWidth() - columnMargin;
       }
     
     Rectangle bounds = table.getCellRect(r0, c0, false);
-    bounds.height = table.getRowHeight()+table.getRowMargin();
-    
+
     // The left boundary of the area being repainted.
     int left = bounds.x;
     
     // The top boundary of the area being repainted.
     int top = bounds.y;
     
     // The bottom boundary of the area being repainted.
     int bottom;
     
-    // The cell height.
-    int height = bounds.height;
-    
     // paint the cell contents
     Color grid = table.getGridColor();    
     for (int r = r0; r <= rn; ++r)
       {
         for (int c = c0; c <= cn; ++c)
           {
             bounds.width = widths[c];
             paintCell(gfx, r, c, bounds, table.getCellRenderer(r, c));
-            bounds.x += widths[c];
+            bounds.x += widths[c] + columnMargin;
           }
-        bounds.y += height;
         bounds.x = left;
+        bounds.y += table.getRowHeight(r) + rowMargin;
+        // Update row height for tables with custom heights.
+        bounds.height = table.getRowHeight(r + 1);
       }
     
-    bottom = bounds.y;
+    bottom = bounds.y - rowMargin;
 
     // paint vertical grid lines
     if (grid != null && table.getShowVerticalLines())
       {    
         Color save = gfx.getColor();
         gfx.setColor(grid);
-        int x = left;
-        
+        int x = left - columnMargin;
         for (int c = c0; c <= cn; ++c)
           {
+            // The vertical grid is draw right from the cells, so we 
+            // add before drawing.
+            x += widths[c] + columnMargin;
             gfx.drawLine(x, top, x, bottom);
-            x += widths[c];
           }
         gfx.setColor(save);
       }
 
     // paint horizontal grid lines    
     if (grid != null && table.getShowHorizontalLines())
       {    
         Color save = gfx.getColor();
         gfx.setColor(grid);
-        int y = top;
+        int y = top - rowMargin;
         for (int r = r0; r <= rn; ++r)
           {
+            // The horizontal grid is draw below the cells, so we 
+            // add before drawing.
+            y += table.getRowHeight(r) + rowMargin;
             gfx.drawLine(left, y, p2.x, y);
-            y += height;
           }
         gfx.setColor(save);
       }
   }
 }
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.80
diff -u -1 -0 -r1.80 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java	10 Mar 2006 22:19:55 -0000	1.80
+++ javax/swing/plaf/metal/MetalLookAndFeel.java	4 May 2006 12:10:54 -0000
@@ -1197,21 +1197,21 @@
       "TabbedPane.shadow", getControlShadow(),
       "TabbedPane.tabAreaBackground", getControl(),
       "TabbedPane.tabAreaInsets", new InsetsUIResource(4, 2, 0, 6),
       "TabbedPane.tabInsets", new InsetsUIResource(0, 9, 1, 9),
       
       "Table.background", getWindowBackground(),
       "Table.focusCellBackground", getWindowBackground(),
       "Table.focusCellForeground", getControlTextColor(),
       "Table.foreground", getControlTextColor(),
       "Table.focusCellHighlightBorder",
-      new BorderUIResource.LineBorderUIResource(getControlShadow()),
+      new BorderUIResource.LineBorderUIResource(getFocusColor()),
       "Table.focusCellBackground", getWindowBackground(),
       "Table.gridColor", getControlDarkShadow(),
       "Table.selectionBackground", new ColorUIResource(204, 204, 255),
       "Table.selectionForeground", new ColorUIResource(0, 0, 0),
 
       "TableHeader.background", getControl(),
       "TableHeader.cellBorder", new MetalBorders.TableHeaderBorder(),
       "TableHeader.foreground", getControlTextColor(),
 
       "TextArea.background", getWindowBackground(),
Index: javax/swing/plaf/metal/OceanTheme.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/OceanTheme.java,v
retrieving revision 1.8
diff -u -1 -0 -r1.8 OceanTheme.java
--- javax/swing/plaf/metal/OceanTheme.java	14 Mar 2006 13:20:18 -0000	1.8
+++ javax/swing/plaf/metal/OceanTheme.java	4 May 2006 12:10:54 -0000
@@ -36,20 +36,21 @@
 exception statement from your version. */
 
 package javax.swing.plaf.metal;
 
 import java.awt.Color;
 import java.awt.Insets;
 import java.util.Arrays;
 
 import javax.swing.UIDefaults;
 import javax.swing.plaf.ColorUIResource;
+import javax.swing.plaf.BorderUIResource.LineBorderUIResource;
 
 /**
  * A modern theme for the Metal Look &amp; Feel.
  * @since 1.5
  *
  * @author Roman Kennke ([EMAIL PROTECTED])
  */
 public class OceanTheme extends DefaultMetalTheme
 {
   /**
@@ -257,20 +258,24 @@
     defaults.put("SplitPane.dividerFocusColor", c1);
     defaults.put("TabbedPane.contentAreaColor", c1);
     defaults.put("TabbedPane.borderHightlightColor", PRIMARY1);
     defaults.put("TabbedPane.selected", c1);
     defaults.put("TabbedPane.tabAreaBackground", c5);
     defaults.put("TabbedPane.unselectedBackground", SECONDARY3);
     defaults.put("Table.gridColor", SECONDARY1);
     defaults.put("ToolBar.borderColor", c3);
     defaults.put("Tree.selectionBorderColor", PRIMARY1);
 
+    // Borders.
+    defaults.put("Table.focusCellHighlightBorder",
+                 new LineBorderUIResource(getPrimary1()));
+
     // Insets.
     defaults.put("TabbedPane.contentBorderInsets", new Insets(4, 2, 3, 3));
     defaults.put("TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6));
 
     // Flags.
     defaults.put("SplitPane.oneTouchButtonsOpaque", Boolean.FALSE);
     defaults.put("Menu.opaque", Boolean.FALSE);
     defaults.put("ToolBar.isRollover", Boolean.TRUE);
     defaults.put("RadioButton.rollover", Boolean.TRUE);
     defaults.put("CheckBox.rollover", Boolean.TRUE);

Reply via email to