My last patch seems to have broken TabbedPane painting slightly. This
was because the order in which the tabs are stored internally has
changed. I fixed this and made the painting code slighly more
straightforward.

2006-03-20  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicTabbedPaneUI.java
        (paint): Make sure the layout is valid before painting.
        (paintTabArea): Made tab painting more straightforward and
efficient.

/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/plaf/basic/BasicTabbedPaneUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTabbedPaneUI.java,v
retrieving revision 1.34
diff -u -r1.34 BasicTabbedPaneUI.java
--- javax/swing/plaf/basic/BasicTabbedPaneUI.java	20 Mar 2006 11:14:06 -0000	1.34
+++ javax/swing/plaf/basic/BasicTabbedPaneUI.java	20 Mar 2006 11:38:07 -0000
@@ -1770,6 +1770,9 @@
    */
   public void paint(Graphics g, JComponent c)
   {
+    if (!tabPane.isValid())
+      tabPane.validate();
+
     if (tabPane.getTabCount() == 0)
       return;
     if (tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT)
@@ -1795,42 +1798,26 @@
     // Please note: the ordering of the painting is important. 
     // we WANT to paint the outermost run first and then work our way in.
     int tabCount = tabPane.getTabCount();
-    int currRun = 1;
-    
-    if (tabCount < 1)
-      return;
-    
-    if (runCount > 1)
-      currRun = 0;    
-    for (int i = 0; i < runCount; i++)
+    for (int i = runCount - 1; i >= 0; --i)
       {
-        int first = lastTabInRun(tabCount, getPreviousTabRun(currRun)) + 1;
-        if (isScroll)
-          first = currentScrollLocation;
-        else if (first == tabCount)
-          first = 0;
-        int last = lastTabInRun(tabCount, currRun);
-        if (isScroll)
+        int start = tabRuns[i];
+        int next;
+        if (i == runCount - 1)
+          next = 0;
+        else
+          next = i + 1;
+        int end = (next != 0 ? next - 1 : tabCount - 1);
+        for (int j = start; j <= end; ++j)
           {
-            for (int k = first; k < tabCount; k++)
+            if (j != selectedIndex)
               {
-                if (rects[k].x + rects[k].width - rects[first].x > viewport
-                    .getWidth())
-                  {
-                    last = k;
-                    break;
-                  }
+                paintTab(g, tabPlacement, rects, j, ir, tr);
               }
           }
-
-        for (int j = first; j <= last; j++)
-          {
-            if (j != selectedIndex || isScroll)
-              paintTab(g, tabPlacement, rects, j, ir, tr);
-          }
-        currRun = getPreviousTabRun(currRun);
       }
-    if (! isScroll)
+
+    // Paint selected tab in front of every other tab.
+    if (selectedIndex >= 0)
       paintTab(g, tabPlacement, rects, selectedIndex, ir, tr);
   }
 

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to