Java Font Display Problem
- by Yan Cheng CHEOK
I realize that, in my certain customer side, when I use the font provided by Graphics2D itself, and decrease the size by 1, it cannot display properly.
private void drawInformationBox(Graphics2D g2, JXLayer<? extends V> layer) {
if (MainFrame.getInstance().getJStockOptions().getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Hide) {
return;
}
final Font oldFont = g2.getFont();
final Font paramFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize());
final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont);
final Font valueFont = new Font(oldFont.getFontName(), oldFont.getStyle() | Font.BOLD, oldFont.getSize() + 1);
final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont);
/*
* This date font cannot be displayed properly. Why?
*/
final Font dateFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize() - 1);
final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont);
Rest of the font is OK. Here is the screen shoot (See the yellow box. There are 3 type of different font within the yellow box) :