when you set the second layout (BorderLayout) you remove the first one (FlowLayout) with all the Buttons on it. Try removing the line "setLayout(new Borderlayout());" and look at the result. HIH ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
The thing is that you have to set only one Layout otherwise the result are not preditable. Why would you want to do what you are doing ??? I don't understand why you want to set a new Layout after setting up all components in your Frame, please light my candle !! And Dong, there is no need for a Panel since the class already extends Frame. HIH ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
Valentin, I came across these questions from Abhilash's Quiz at http://www.angelfire.com/or/abhilash/Main.html. Since I dont find explanation for the answers in that site I posted the same here.
Ok I'll give it a shot. The main difference is that FlowLayout implements LayoutManager and BorderLayout implements LayoutManager2. A second difference is that FlowLayout does not keep trace of the components in the layout while BorderLayout does. When you set a new Layout on a Container, the Container invokes the method invalidateLayout() upon the LayoutManager if and only if the layout manager implements LayoutManager2 which is the case of BorderLayout. So in clear: In the first code, when you set the second layout (BorderLayout) the latter has no references to the added components, so nothing is displayed. In the second case, when you set the second layout (FlowLayout) it asks the container about the list of its components and displays them according to its layout policy. HIH ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
Valentin, thankyou very much for this explanation about LayoutManager. I need explanation for the other answers in Abhilash's Quiz. So if you anyone has explanation for all the answers in Abhilash's Quiz please let me know. I have written to the author, but I haven't heard from him so far. Thanks, Malar.
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad: