changeset 17767:fd9a519897e5

8075918: The regression-swing case failed as the long Tab titles are not clipped with dots at the end with NimbusLookAndFeel Reviewed-by: serb, aniyogi
author psadhukhan
date Wed, 21 Jun 2017 10:30:25 +0530
parents 0ec14d6528ef
children 4cdd5d954479
files src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java src/java.desktop/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java test/javax/swing/JTabbedPane/4310381/bug4310381.java
diffstat 4 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java	Sun Jun 18 19:52:09 2017 +0530
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java	Wed Jun 21 10:30:25 2017 +0530
@@ -1138,7 +1138,11 @@
                              int tabIndex, Icon icon, Rectangle iconRect,
                              boolean isSelected ) {
         if (icon != null) {
+            // Clip the icon within iconRect bounds
+            Shape oldClip = g.getClip();
+            ((Graphics2D)g).clip(iconRect);
             icon.paintIcon(tabPane, g, iconRect.x, iconRect.y);
+            g.setClip(oldClip);
         }
     }
 
--- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java	Sun Jun 18 19:52:09 2017 +0530
+++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java	Wed Jun 21 10:30:25 2017 +0530
@@ -326,7 +326,11 @@
      */
     public void paintText(SynthContext ss, Graphics g, String text,
                           Rectangle bounds, int mnemonicIndex) {
+        // Clip the text within textRect bounds
+        Shape oldClip = g.getClip();
+        ((Graphics2D)g).clip(bounds);
         paintText(ss, g, text, bounds.x, bounds.y, mnemonicIndex);
+        g.setClip(oldClip);
     }
 
     /**
--- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java	Sun Jun 18 19:52:09 2017 +0530
+++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java	Wed Jun 21 10:30:25 2017 +0530
@@ -621,15 +621,17 @@
 
         if (tabPane.getTabComponentAt(tabIndex) == null) {
             String title = tabPane.getTitleAt(tabIndex);
+            String clippedTitle = title;
             Font font = ss.getStyle().getFont(ss);
             FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
             Icon icon = getIconForTab(tabIndex);
 
             layoutLabel(ss, tabPlacement, metrics, tabIndex, title, icon,
                     tabRect, iconRect, textRect, isSelected);
-
+            clippedTitle = SwingUtilities2.clipStringIfNecessary(null, metrics,
+                           title, textRect.width);
             paintText(ss, g, tabPlacement, font, metrics,
-                    tabIndex, title, textRect, isSelected);
+                    tabIndex, clippedTitle, textRect, isSelected);
 
             paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
         }
--- a/test/javax/swing/JTabbedPane/4310381/bug4310381.java	Sun Jun 18 19:52:09 2017 +0530
+++ b/test/javax/swing/JTabbedPane/4310381/bug4310381.java	Wed Jun 21 10:30:25 2017 +0530
@@ -27,7 +27,7 @@
 
 /*
  * @test
- * @bug 4310381
+ * @bug 4310381 8075918
  * @summary Text in multi-row/col JTabbedPane tabs can be truncated/clipped
  * @author Charles Lee
    @run applet/manual=yesno bug4310381.html