Search code examples
javapaneljscrollpanerepaint

JScrollPane always clears my Panel


Hy.. I have a JPanel, and in this contentPanel I added some other custom panels and give them locations etc. So now I added a JScrollPane to the contentPanel and always when I scroll down it clears my contentPanel, but the panels are still there but not visible...

How can I make them visible again?

That's my code to add the Panel into the contentPanel. The x,y,j are some settingsstuff for the location because I have an fixed window.

private void reloadContentPanel() {

    int x = -200, y = 0, j = 1, row = 4;
    EventPanel panel = null;

    int i;
    for(i=0; i < this.images.size();i++)
    {
        panel = new EventPanel(this.images.get(i).getAbsolutePath(), 
                               this.images.get(i).getName());

        panel.setLocation(x+(j*200), y);
        j++;
        if(i == row) {
            x = -200;
            y += 205;
            j = 1;
            row += 5;
        }
        this.contentPanel.add(panel);
    }
    this.repaint();
}

Thanks


Solution

  • I have the answer! :)

    I use a GridLayout not a FlowLayout, so it's fine and it automatically refreshes the panels =)