views:

27

answers:

3

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

A: 

[CODE POSTED HERE WAS MOVED BACK TO THE QUESTION]

fuzi-
it's better to edit your question and include this than to post an answer which isn't really an answer. StackOverflow isn't like regular forums.
pstanton
+1  A: 

it sounds like you are not using a LayoutManager correctly.

after creating your JFrame (i'm guessing within your constructor) add the following (for example):

this.setLayout(new FlowLayout());

this will certainly not be the best layout manager for what you are trying to do but will stop the add calls from overriding the displayed component.

you will need to read further about LayoutManagers

besides this, it's not really advisable to extend JFrame. It's better practice to treat JFrame as a member of your class just like all the other components.

pstanton
bragboy, i know what i wrote.
pstanton
You think if I set the Layout to FlowLayout it will add my panels automatically in the right position? I tried it and the panels are in the same position like the first. (overlapped)
fuzi-
A: 

I have the answer! :)

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

fuzi-