JDK-4194023 : JEditorPane presents selection problems when anti-aliasing is turned on
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 1998-12-02
  • Updated: 2007-07-18
Related Reports
Duplicate :  
Relates :  
Description

Name: gsC80088			Date: 12/01/98


The following code fragment just opens a frame with
a JEditorPane in it, but with text anti-aliasing 
turned on. On both PC's I ran this on, trying to
edit/highlight text causes a complete mess.

Other related problems I've had with text anti-aliasing 
include JInternalFrame title bars drawing over the 
end of the title text, and button labels drawing
incorrectly.

It all appears to be related to FontMetrics not
returning the correct width for a line of text.


import java.awt.*;
import javax.swing.*;


public class Test extends JFrame
{
    public static void main (String[] args)
    {
        JFrame f = new Test();
        f.setBounds (50, 50, 400, 400);
        f.setVisible (true);
    }

    public Test()
    {
        JEditorPane ed = new JEditorPane()
        {
            public void paint (Graphics g)
            {
                if (g instanceof Graphics2D)
                {
                    ((Graphics2D)g).setRenderingHint (RenderingHints.KEY_TEXT_ANTIALIASING,
                                                      RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

                    ((Graphics2D)g).setRenderingHint (RenderingHints.KEY_FRACTIONALMETRICS,
                                                      RenderingHints.VALUE_FRACTIONALMETRICS_ON);

                }
                
                super.paint (g);
            }
        };

        ed.setBackground (Color.white);
        ed.setVisible (true);
        ed.setFont (new Font ("SansSerif", Font.BOLD, 15));

        setContentPane (ed);
    }
}
(Review ID: 43510)
======================================================================

Comments
EVALUATION swing text does not support anti-aliasing yet. Currently we are using font metrics for default graphics. We should layout text on java.awt.font.FontRenderContext basis. Also new API should be introduced to turn on anti-aliasing for text. ###@###.### 2002-05-13
13-05-2002