i simply implemented class that inherits JPanel like below
public class Orpanel extends JPanel {
....
@Override
public void paintComponent(Graphics
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.
Sounds like you're just using the wrong methods. You should be doing this when adding a panel to a frame:
frame.getContentPane().add(panel) ;