JPanel doesn't update until resize Jframe

前端 未结 5 961
孤独总比滥情好
孤独总比滥情好 2020-12-01 20:58

I subclass JPanel to overwrite paintComponent(Graphics), I want to draw an image onto jpanel in a jframe.

But my image hasn\'t shown up until I make a change to jfra

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 21:22

    Verify that you invoke setVisible() after adding components and calling pack(), as discussed in this related example. You may also need to adopt an appropriate layout. Invoking repaint(), as suggested here, may fix the symptom but not the underlying cause.

提交回复
热议问题