I have something I need to draw on the screen, but that requires font metrics to draw correctly. I also need to use repaint() or something else to draw to the screen right then and there.
If I have a paintComponent(Graphics)
method, I can retrieve the font metrics correctly via g.getFontMetrics(g.getFont())
. The problem is, I cannot tell it to paint it's self. It only does it when something happens such as the component being resized.
Then if I use just normal paint(Graphics)
, I may use repaint()
to draw when I want it to, but calling g.getFontMetrics(g.getFont())
does not return correct values. Any ideas?
repaint();//I need to call repaint() or something similar to draw to the screen when I want it to
public void paint(Graphics g){
FontMetrics metrics = g.getFontMetrics(g.getFont());//Returns different metrics than that of paintComponent(Graphics)
}
public void paintComponent(Graphics g){
FontMetrics metrics = g.getFontMetrics(g.getFont());//Returns different metrics than that of paint(Graphics)
}