This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

why layout managers

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am wondering abt the need of layout managers when i have fixed size containers.I can might as well use a null layout and setBounds to all the child components.
Please let me know if i am to consider anything else when taking a call whether or not use a layout manager.
william
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with using a null layout and setbounds are many. But to name a few...
  • If your window is resized for any reason, your components won't adjust accordingly. So components might render off screen and the user won't see them.
  • Different OS's display components differently. A JButton of size 20x100 isn't the same size on Linux as it is on Windows. Also, the size could change just by using different L&F's. When you specify a location and size, it's not really pixals, cm, or any amount of measurement that is consistant.
  • Fonts - Similar to the affor mentioned problem, Fonts display differently on different OS's. So a static sized Component in Windows that displays the text "Push Me" might display "Push M.." in Linux.


  • I used to always use null layouts with setBounds(...) but I have been trying lately to use Layout Managers. Some of them are tricky at first but taking a day or 2 to learn them will save you days of headaches when the user calls and complains that the GUI looks funny on the OS at nnn X nnn resolution.
     
    william kane
    Ranch Hand
    Posts: 260
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Originally posted by Gregg Bolinger:
    The problem with using a null layout and setbounds are many. But to name a few...

  • If your window is resized for any reason, your components won't adjust accordingly. So components might render off screen and the user won't see them.
  • Different OS's display components differently. A JButton of size 20x100 isn't the same size on Linux as it is on Windows. Also, the size could change just by using different L&F's. When you specify a location and size, it's not really pixals, cm, or any amount of measurement that is consistant.
  • Fonts - Similar to the affor mentioned problem, Fonts display differently on different OS's. So a static sized Component in Windows that displays the text "Push Me" might display "Push M.." in Linux.


  • I used to always use null layouts with setBounds(...) but I have been trying lately to use Layout Managers. Some of them are tricky at first but taking a day or 2 to learn them will save you days of headaches when the user calls and complains that the GUI looks funny on the OS at nnn X nnn resolution.


    Thanks greg i will consider your observations thanks a million
     
    Ranch Hand
    Posts: 580
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you use the NullLayout adding new components to your forms can be a real nightmare. You have to manually update loads of your components to accomoadate the new one.
    This is easier if you use a gui builder but IMO you shouldnt use a gui builder for production code.
    Using layout managers makes adding/removing components easier.
    D.
     
    Shiny 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
      Bookmark Topic Watch Topic
    • New Topic