JDK-8169719 : WrappedPlainView.modelToView() should return Rectangle2D
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-11-15
  • Updated: 2016-12-22
  • Resolved: 2016-11-21
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 b150Fixed
Related Reports
Relates :  
Description
Steps to reproduce:
- Run the following sample on HiDPI display or with property -Dsun.java2d.uiScale=2
------------------
import java.awt.FlowLayout;
import java.awt.geom.Rectangle2D;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.text.JTextComponent;

public class JEditorPaneModelToView2DTest {

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(JEditorPaneModelToView2DTest::createAndShowGUI);
    }

    private static void createAndShowGUI() {

        JFrame frame = new JFrame();
        try {
            frame.setSize(300, 300);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JPanel panel = new JPanel(new FlowLayout());
            JTextField textField = new JTextField();
            JTextArea textArea = new JTextArea();
            JEditorPane editorPane = new JEditorPane();

            panel.add(textField);
            panel.add(textArea);
            panel.add(editorPane);

            frame.getContentPane().add(panel);
            frame.setVisible(true);

            String text = "aaaa";

            testTextComponent(textField, text);
            testTextComponent(textArea, text);
            testTextComponent(editorPane, text);
        } catch (Exception e) {
            throw e;
        } finally {
            frame.setVisible(false);
        }
    }

    static void testTextComponent(JTextComponent textComponent, String text) {
        textComponent.setText(text);

        for (int i = 0; i < text.length(); i++) {
            try {
                Rectangle2D rect = textComponent.modelToView2D(i);
                System.out.println("text: '" + text.substring(0, i) + "', x: " + rect.getX());
                if (isFloatingPointValue(rect.getX())) {
                    return;
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        throw new RuntimeException(textComponent.getClass() + ".modelToView2D()"
                + " does not contain floating point coordinates!");
    }

    static boolean isFloatingPointValue(double x) {
        return x != (int) x;
    }
}
------------------

The result is:

class javax.swing.JTextField
text: '', x: 2.0
text: 'a', x: 8.5
class javax.swing.JTextArea
text: '', x: 0.0
text: 'a', x: 6.5
class javax.swing.JEditorPane
text: '', x: 3.0
text: 'a', x: 10.0
text: 'aa', x: 16.0
text: 'aaa', x: 23.0
Caused by: java.lang.RuntimeException: class javax.swing.JEditorPane.modelToView2D() does not contain floating point coordinates!