United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6797139 JButton title is truncating for some strings irrespective of preferred size.
JDK-6797139 : JButton title is truncating for some strings irrespective of preferred size.

Details
Type:
Bug
Submit Date:
2009-01-23
Status:
Resolved
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2009-09-16
Component:
client-libs
OS:
windows_vista,generic,windows_xp
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Backport:
Duplicate:
Duplicate:
Relates:
Relates:
Relates:

Sub Tasks

Description
JButton title is truncating for some strings irrespective of preferred size.I have set different titles to JButton and expected the title should appear in the Button.
But for some strings the title is truncating with three dots.

I have set a "Probably" string to JButton as title and I would expected the button should show given string as title.But it shows "Proba..." by truncating with dots.

It works fine with 6ur builds.I could see this issue only with JDK7

JDK Version
===========
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b43)
Java HotSpot(TM) Client VM (build 14.0-b10, mixed mode)

Please run the attached code for reproducing the issue.
Also seen content in the OptionPane Dialogs getting truncated similarly in jdk7 b46

                                    

Comments
EVALUATION

This is a regression from the fix for the bug #6464003,
after that fix we pay attention to the left and right text bearings.
In the provided test case the right bearing of the text "Probably" is 1,
because the letter "y" is sligtly overlaps the text bounds,
it leads to the fact that SwingUtilities.layoutCompoundLabelImpl() 
assumes that text width is more than the view width and clip the text.

The suggested fix:
We shouldn't clip the text and add ellipsis at the end
if we didn't do it before, so I suggest calculate if we need to clip the text
without bearings first and take bearing into account only after that

SwingUtilities.layoutCompoundLabelImpl()

lines 1008 - 1034

                // moved it from the label 1:
                // clip the text here, before working with bearings
                if (textR.width > availTextWidth) {
                    text = SwingUtilities2.clipString(c, fm, text,
                                                      availTextWidth);
                    textR.width = SwingUtilities2.stringWidth(c, fm, text);
                }
                
                // Take into account the left and right side bearings.
                // This gives more space than it is actually needed,
                // but there are two reasons:
                // 1. If we set the width to the actual bounds,
                //    all callers would have to account for the bearings
                //    themselves. NOTE: all pref size calculations don't do it.
                // 2. You can do a drawString at the returned location
                //    and the text won't be clipped.
                lsb = SwingUtilities2.getLeftSideBearing(c, fm, text);
                if (lsb < 0) {
                    textR.width -= lsb;
                }
                rsb = SwingUtilities2.getRightSideBearing(c, fm, text);
                if (rsb > 0) {
                    textR.width += rsb;
                }                      
                // label 1:
                                     
2009-01-26
EVALUATION

It was decided to completely roll back the fix of the bug #6464003
                                     
2009-08-21



Hardware and Software, Engineered to Work Together