Any alternative to calling getGraphics() which is returning null

后端 未结 2 1496
南方客
南方客 2020-11-30 11:53

Frequently when I call getGraphics() it returns null, even if I set the xxx.getGraphics(); xxx to be visible (as a Google search shows...)

But this doesn\'t work, a

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 12:32

    Don't use getGraphics(). Any painting you do will be temporary and will be lost the next time Swing determines a component needs to be repainted.

    Instead override the paintComponent() method of a JComponent or JPanel to do your custom painting. See Custom Painting for more details and examples.

提交回复
热议问题