I have a simple question. I want to move a JPanel (inside an another JPanel) a little each step, so it will looks like moving continuously ('Number' is my class extending JPanel):
Number n = (Number)this.findComponentAt(x, y);
for(int pp= 0; pp<10; pp++){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
n.setLocation(x-10*pp, y);
n.repaint();
}
The paintComponent method for Number is:
public void paintComponent(Graphics g){
super.paintComponent(g);
numIc.paintIcon(this, g, 0, 0);
}
However, it is not moving step by step but moving suddenly to final destination after 10 delays! I searched questions but didn't find helpful answers.