-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.2beta4
-
x86
-
solaris_2.6, windows_95, windows_nt
-
Not verified
Name: rm29839 Date: 01/06/98
please compile and run
import java.awt.*;
import java.awt.event.*;
import java.awt.swing.*;
public class TestFont extends JFrame {
public static void main(String[] args ) {
TestFont tsb = new TestFont();
tsb.show();
}
public TestFont() {
setBounds(20,20,400,600);
setBackground(Color.white);
setFont( new Font("SansSerif",Font.BOLD,20));
JPanel p = new FontPanel();
getContentPane().add("Center",p);
}
}
class FontPanel extends JPanel {
public void paint(Graphics g) {
int leftMargin = 20;
int y = 120;
//g.setFont( new Font("SansSerif",Font.BOLD,20)); tried this with same effect.
g.drawString("AB CDI Ii iJWjk", leftMargin, y);
int W = getFontMetrics(g.getFont()).stringWidth("AB CDI Ii iJWjk");
g.drawLine(leftMargin,y,leftMargin + W,y);
}
}
You will notice that the underline is much longer than the text string.
If you replace the JPanel by Panel and JFrame by Frame and replace the getContentPane() by a simple add()
you will get an AWT version which underlines to the same length as the drawn text.
Have a Very Good Xmas good wishes for the New Year.
Regards Peter Wilson
(Review ID: 22445)
======================================================================
- duplicates
-
JDK-4113590 Label on JButton widget truncated due to layout bug.
-
- Closed
-
- relates to
-
JDK-4130434 The Measurement of Text
-
- Closed
-