Withdrawn: 6734168: BasicButtonUI uses wrong FontMetrics to Layout JButtons text

duke duke at openjdk.org
Sat May 17 02:01:01 UTC 2025


On Fri, 21 Mar 2025 11:26:34 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> javax.swing.plaf.basic.BasicButtonUI uses wrong FontMetrics object to layout the text on a JButton. 
> The paint(Graphics, JComponent) method of BasicButtonUI calculates the [FontMetrics](https://github.com/openjdk/jdk/blob/6656254c346ef505a48652fdf4dedd6edc020e33/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonUI.java#L331) using the passed Graphics object without setting the buttons font before. If the buttons font varies from the currently set font of the passed graphics object, the font metrics do not fit the metrics of the expected font leading to truncated text on the button.
> In WindowsLookAndFeel, the font in passed graphics object differs from currently set font as in 
> 
> button font javax.swing.plaf.FontUIResource[family=Tahoma,name=Tahoma,style=plain,size=10] 
> graphics font java.awt.Font[family=Dialog,name=Dialog,style=plain,size=12]
> 
> whereas in Metal and other L&F it is 
> `font javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=bold,size=12]`
> 
> so the fix is made in Windows L&F to ensure to set the font of the button to the passed graphics object font before calculating the current FontMetrics.

This pull request has been closed without being integrated.

-------------

PR: https://git.openjdk.org/jdk/pull/24152


More information about the client-libs-dev mailing list