-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b56
-
x86
-
windows_xp
Name: rmT116609 Date: 02/25/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Under the Microsoft Windows Look and Feel, by default unselected text is painted black and selected text is painted white.
In tiger-beta JTextPanes, this behavior has changed from selected vs. unselected text to highlighted vs. unhighlighted text.
If you create a JTextPane and attach a highlight to a portion of its text, that text will be painted in the selected text color even if it is not selected. Since the selected text color and the text pane background both default to white, this results in the highlighted text seemingly disappearing.
I have traced the problem to a change in GlyphView.paint. The paint method was deliberately modified to look for highlights instead of selection, but I am not sure why. If this was an intentional change in behavior (I hope not), it should be applied to all text components and not just JTextPane, for consistency.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached test case on a Microsoft Windows machine.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Both the JTextArea and the JTextPane should display selected text in white and unselected text in black (assuming default color choices).
ACTUAL -
Under tiger-beta, the JTextPane displays the underlined text in white instead of black. The JTextArea behaves properly.
Under previous versions of Java, both components display correctly.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.text.*;
public class HighlightTest {
private static class TestHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter {
public TestHighlightPainter() {
super(Color.RED);
}
public Shape paintLayer(Graphics gc, int offs0, int offs1,
Shape bounds, JTextComponent c, View view) {
try {
Graphics2D g = (Graphics2D) gc;
Shape shape = view.modelToView(offs0, Position.Bias.Forward,
offs1, Position.Bias.Backward,
bounds);
Rectangle r = (shape instanceof Rectangle) ?
(Rectangle) shape : shape.getBounds();
g.setColor(Color.RED);
g.fillRect(r.x, r.y + r.height - 3, r.width, 1);
return r;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
public static void main(String[] arg) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JTextPane textPane = new JTextPane();
textPane.setText("Example Text Pane");
textPane.getHighlighter().addHighlight(1, 4, new TestHighlightPainter());
textPane.setBackground(new Color(192, 192, 255));
JTextArea textArea = new JTextArea();
textArea.setText("Example Text Area");
textArea.getHighlighter().addHighlight(1, 4, new TestHighlightPainter());
textArea.setBackground(new Color(192, 192, 255));
JFrame f = new JFrame();
f.getContentPane().setLayout(new GridLayout(2, 1));
f.getContentPane().add(new JScrollPane(textArea));
f.getContentPane().add(new JScrollPane(textPane));
f.setSize(200, 200);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.show();
}
}
---------- END SOURCE ----------
Release Regression From : 1.4.2
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Incident Review ID: 240223)
======================================================================
- relates to
-
JDK-5101869 REGRESSION: Arabic Text Does Not Repaint Correctly After Being Selected
- Closed
-
JDK-4761990 1.4 REGRESSION: Highlighting Color Behavior has changed
- Closed