JDK-6797139 : JButton title is truncating for some strings irrespective of preferred size.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_xp,windows_vista
  • CPU: generic,x86
  • Submitted: 2009-01-23
  • Updated: 2011-01-19
  • Resolved: 2009-09-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u21Resolved 7 b72Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
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 It was decided to completely roll back the fix of the bug #6464003
21-08-2009

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:
26-01-2009