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)
======================================================================