Here is the thing:
public class ParentPanel extends JPanel{
private ChildPanel childPanel;
public ParentPanel() {
super();
initComponents();
}
public void pushData(int data){
childPanel.pushData(data);
}
private void initComponents() {
childPanel= new ChildPanel();
}
I have another class:
public class ChildPanel extends JPanel{
public ChildPanel(){
super();
}
public void paintComponent(Graphics g){
//I draw some lines in this JPanel according to data
}
public void pushData(int data){
repaint();
}
}
What I want is to draw some lines when the pushData() method inside ChildPanel is called. But now there is no responding inside the ChildPanel. What should I do?
childPanelis not part of any container, itspaintComponentis not going to be called. Try adding it as a child toParentPanel, ie insideinitComponentscalladd(childPanel).EDIT: sample based on posted code