JDK-8132119 : Provide public API for text related methods in SwingUtilities2
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: other
  • CPU: x86
  • Submitted: 2015-07-17
  • Updated: 2019-03-18
  • Resolved: 2016-07-05
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 9
9 b127Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
SwingUtilities2 provides a number of methods and fields related to drawing and measuring text. These methods and fields are widely used in platform LAFs. They support text anti-aliasing and compatibility of rendering for printing and display. This functionality should be provided in a public API for use by third party LAFs in JDK9 and beyond.

The relevant methods and fields are:

drawString(JComponent, Graphics, String, int, int)
drawStringUnderlineCharAt
clipStringIfNecessary
stringWidth
getFontMetrics(JComponent, Graphics)
AATextInfo.getAATextInfo
AA_TEXT_PROPERTY_KEY

These methods and fields support anti-aliasing features that perhaps could be duplicated using public APIs, but it would be a lot of work.

These methods also use private APIs to obtain a Graphics2D from the Graphics object used in the printing APIs, so that text rendering when printing can be the same as on a display.

The Aqua LAF does something similar with printer graphics in AquaPainter.getGraphics2D. The fact that it is not exactly the same should be investigated.

These symbols are less widely used but should also be considered:

COMPONENT_UI_PROPERTY_KEY
BASICMENUITEMUI_MAX_TEXT_OFFSET

This RFE should be have labels "modularization" and "jdkinternals".


JUSTIFICATION :
It should be possible to write custom LAFs that have the same abilities as platform LAFs. In JDK9, the internal APIs used by platform LAFs will no longer be available outside the JDK. Hence, public APIs are needed.



Comments
FC Extension Request remaining work to be done: the API is proposed and the CCC request is approved the risk level: low brief justification: Swing uses methods with integer arguments to draw a text and a selected text. The char advance can have floating point values on HiDPI display. Swing API should be updated to add text drawing methods with floating point values. estimate of the date by which the feature will be complete: July 15
04-07-2016

The updated version: http://cr.openjdk.java.net/~alexsch/8132119/webrev.12/ See the discussion: http://mail.openjdk.java.net/pipermail/swing-dev/2016-May/005871.html
11-05-2016

It was commented on the review that new drawString()/getStringWidth() methods should use fractional sizes: http://mail.openjdk.java.net/pipermail/swing-dev/2016-April/005795.html This also requires that additional methods with fractional sizes will be added to existed ones: javax.swing.text.Utilities.drawTabbedText(...) javax.swing.text.Utilities.getTabbedTextWidth(...) javax.swing.text.Utilities.getTabbedTextOffset(...) javax.swing.text.Utilities.getBreakLocation(...) javax.swing.text.PlainView.getTabSize(...) javax.swing.text.PlainView.drawLine(...) javax.swing.text.PlainView.drawUnselectedText(...) javax.swing.text.PlainView.drawSelectedText(...)
10-05-2016

The latest discussion on the review alias: http://mail.openjdk.java.net/pipermail/swing-dev/2016-April/005795.html
10-05-2016

Alexandr, did you get it reviewed?
04-03-2016

The fix is discussed on the review: http://mail.openjdk.java.net/pipermail/swing-dev/2016-January/005361.html
25-01-2016

This bug is "In Progress" status now, so re-targeting back to Fix Version 9. If you are not working on this bug fix anymore, please update the bug from "In Progress" to just "Open"
13-11-2015

Antialiasing properties are covered by JDK-6302464 Allow programmatic enabling of subpixel anti-aliasing in Swing COMPONENT_UI_PROPERTY_KEY property is covered by JDK-4339584 Adding a getUI public method to JComponent
02-09-2015

This may be a dup of JDK-8064785.
23-07-2015