• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Layout

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Valentin, but the following code displays all five buttons with FlowLayout, though BorderLayout is set initially.
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic