RFR: 5108458: JTable does not properly layout its content [v5]

Prasanta Sadhukhan psadhukhan at openjdk.org
Tue Nov 21 08:13:07 UTC 2023


On Tue, 21 Nov 2023 04:02:52 GMT, Tejesh R <tr at openjdk.org> wrote:

>>> LTR doesn't need getXPosition
>> 
>> But it is called in `if (table.getComponentOrientation().isLeftToRight()) `condition above
>
> Yes, actually it is not required because it gives/should give the same x position value. Have to remove it, might have added for checking if it had any effect on LTR.

I guess you can simplify the fix without using `getXPosition`..You probably would still need `getWidthInRIghtToLeft` but as suggested, having an unified method in a common class like SwingUtilities2 is desirable...Let me know if this will work..


--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java
@@ -2028,9 +2028,19 @@ private void paintGrid(Graphics g, int rMin, int rMax, int cMin, int cMax) {
         if (table.getShowHorizontalLines()) {
             int tableWidth = damagedArea.x + damagedArea.width;
             int y = damagedArea.y;
-            for (int row = rMin; row <= rMax; row++) {
-                y += table.getRowHeight(row);
-                SwingUtilities2.drawHLine(g, damagedArea.x, tableWidth - 1, y - 1);
+            if (table.getComponentOrientation().isLeftToRight()) {
+                for (int row = rMin; row <= rMax; row++) {
+                    y += table.getRowHeight(row);
+                    SwingUtilities2.drawHLine(g, damagedArea.x, tableWidth - 1, y - 1);
+                }
+            } else {
+                TableColumnModel cm = table.getColumnModel();
+                for (int row = rMax; row >= rMin; row--) {
+                    y += table.getRowHeight(row);
+                    int w = cm.getColumn(cMax).getWidth();
+                    damagedArea.x = table.getWidth() - (w * (cMax + 1));
+                    SwingUtilities2.drawHLine(g, damagedArea.x, table.getWidth() - 1, y - 1);
+                }
             }
         }
         if (table.getShowVerticalLines()) {
@@ -2090,18 +2100,12 @@ private void paintCells(Graphics g, int rMin, int rMax, int cMin, int cMax) {
             }
         } else {
             for(int row = rMin; row <= rMax; row++) {
-                cellRect = table.getCellRect(row, cMin, false);
-                aColumn = cm.getColumn(cMin);
-                if (aColumn != draggedColumn) {
-                    columnWidth = aColumn.getWidth();
-                    cellRect.width = columnWidth - columnMargin;
-                    paintCell(g, cellRect, row, cMin);
-                }
-                for(int column = cMin+1; column <= cMax; column++) {
+                for(int column = cMin; column <= cMax; column++) {
+                    cellRect = table.getCellRect(row, column, false);
                     aColumn = cm.getColumn(column);
                     columnWidth = aColumn.getWidth();
                     cellRect.width = columnWidth - columnMargin;
-                    cellRect.x -= columnWidth;
+                    cellRect.x = table.getWidth() - (columnWidth * (column + 1));
                     if (aColumn != draggedColumn) {
                         paintCell(g, cellRect, row, column);

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16374#discussion_r1400168991


More information about the client-libs-dev mailing list