Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why layout managers

 
william kane
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
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • 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
     
    Don Kiddick
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic