Swing - paintComponent method not being called

后端 未结 2 550
面向向阳花
面向向阳花 2020-12-21 00:42

i simply implemented class that inherits JPanel like below

public class Orpanel extends JPanel {

....
    @Override
    public void paintComponent(Graphics          


        
2条回答
  •  醉酒成梦
    2020-12-21 00:50

    In your sample code, I see you have chosen NOT to use a LayoutManager, that's a very bad idea, but anyway, sicne you go this way, I see one reason for your Orpanel.paintComponent() not being called: it is probably not visible inside the frame!

    If you have no LayoutManager, then you must explicitly set the size and location (through setBounds()) of all components you add to the frame.

    It is likely you didn't do it, hence the size of Orpanel instance is probably 0 hence it never gets painted.

提交回复
热议问题