8075918: The regression-swing case failed as the long Tab titles are not clipped with dots at the end with NimbusLookAndFeel
authorpsadhukhan
Wed, 21 Jun 2017 10:30:25 +0530
changeset 47139 0cbe21f1eb04
parent 47138 13655aba48b7
child 47140 519fd8ec4ce1
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
jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java
jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java
jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java
jdk/test/javax/swing/JTabbedPane/4310381/bug4310381.java
--- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java	Sun Jun 18 19:52:09 2017 +0530
+++ b/jdk/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/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java	Sun Jun 18 19:52:09 2017 +0530
+++ b/jdk/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/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java	Sun Jun 18 19:52:09 2017 +0530
+++ b/jdk/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/jdk/test/javax/swing/JTabbedPane/4310381/bug4310381.java	Sun Jun 18 19:52:09 2017 +0530
+++ b/jdk/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