This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Layout

 
Malar Ravi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dong Fu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a Panel and then add your buttons in the panel.
HIH
Dong
 
Malar Ravi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Valentin, but the following code displays all five buttons with FlowLayout, though BorderLayout is set initially.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic