Adding to a form

I have a question, that I hope is a rather easy one to answer.

Is it true that once you add something to a particular space on a form, using border layout, and then add something else on top of that, it destroys what's behind it? Such as, if when I initalize my program, I have a statement like this:

Button1.setVisible(false);

Button2.setVisible(true);

form.add(Button1, BorderLayout.CENTER);

form.add(Button2, BorderLayout.CENTER);

Because I added Button2 second, it will display. However, if I try something like the following later on in the program:

Button2.setVisible(false);

Button1.setVisible(true);

Button2 will indeed dissapear, however, Button1 will not show itself. Is this because I've added both to the same location on the BorderLayout? What would be a better way of doing this? Thanks for any input received.

[894 byte] By [sbsquarepants] at [2007-9-26 1:20:27]
# 1

Yes, as far as I know, by adding Button2 to CENTER after Button1, you are effectively removing Button1 from the window.

So you can call Button1.setVisible(true), but since Button1 is no longer on any window, you won't see it.

I think you'd be better off looking at CardLayout instead of BorderLayout. CardLayout allows you to place components in front of each other, and flip between them, so you only see one at a time, but they're all still there.

peeveen at 2007-6-29 0:54:35 > top of Java-index,Desktop,Core GUI APIs...