aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Layout" Watch "Layout" New topic
Author

Layout

Malar Ravi
Ranch Hand

Joined: Oct 15, 2001
Posts: 51
Could someone explain me why none of the buttons are displayed. If this question has already been asked, please provide me the link.

Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Dong Fu
Greenhorn

Joined: Nov 19, 2001
Posts: 9
You need a Panel and then add your buttons in the panel.
HIH
Dong
Malar Ravi
Ranch Hand

Joined: Oct 15, 2001
Posts: 51
Valentin, but the following code displays all five buttons with FlowLayout, though BorderLayout is set initially.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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
Malar Ravi
Ranch Hand

Joined: Oct 15, 2001
Posts: 51
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.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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
Malar Ravi
Ranch Hand

Joined: Oct 15, 2001
Posts: 51
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Layout