-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0
-
beta
-
generic, x86
-
generic, windows_nt
Name: boT120536 Date: 12/27/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
I am resubmitting this bug. It is not a duplicate of Bug ID: 4104267. That
bug is about the bad width of non printable characters. This bug is that
fontWidth is returning a zero for a character that takes up space when printed.
Another possibly related bug I have since found is that KeyEvent.CHAR_UNDEFINED
is not drawn. It should probably be printed with a box like other non
printable characters.
Here is my original bug report:
There are two related problems here. First, drawString draws a box that takes
up space for non printable characters, but FontMetrics.stringWidth does
not include this space. This makes it impossible to line up two different
pieces of text.
The second problem is that the box drawn is bigger than the characters in the
font, even for a fixed width font.
On jdk 1.8 all of this works properly, probably because a ? character is drawn
instead of a box.
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Frame;
import java.awt.Font;
class test3 extends Canvas {
static String str ="abc\t123\nasdfasdfasdfasdf";
test3() {
super();
}
private static String fontname = "Courier New";
private static int fontsize= 30;
private static int fonttype = Font.PLAIN;
public void paint(Graphics g) {
g.drawString(str,50, 50);
int newx = getFontMetrics(getFont()).stringWidth("\t");
System.out.println("font = " + getFont());
System.out.println("stringWidth = " + newx);
System.out.println("stringWidth t = " +
getFontMetrics(getFont()).stringWidth("t"));
System.out.println("string bounds = " + getFont().getStringBounds(
"\t",((Graphics2D)g).getFontRenderContext()));
System.out.println("string bounds = " + getFont().getStringBounds(
"t",((Graphics2D)g).getFontRenderContext()));
}
public static void main (String args[]) {
Frame fr = new Frame("test3 frame");
test3 inst = new test3();
inst.setFont(new Font(fontname,fonttype,fontsize));
inst.setSize(200,200);
fr.add(inst);
fr.pack();
inst.setVisible(true);
fr.setVisible(true);
}
}
(Review ID: 114220)
======================================================================
- duplicates
-
JDK-4398837 Inconsistent handling of nonprintable characters in JTextArea
-
- Closed
-