wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes why layout managers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "why layout managers" Watch "why layout managers" New topic
Author

why layout managers

william kane
Ranch Hand

Joined: Nov 21, 2000
Posts: 260
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


Help me!Help you!!!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


    GenRocket - Experts at Building Test Data
    william kane
    Ranch Hand

    Joined: Nov 21, 2000
    Posts: 260
    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

    Joined: Dec 12, 2002
    Posts: 580
    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: why layout managers
     
    Similar Threads
    Reg. AWT components
    Decrese space between Jlabel and its container(as cell spacing in html)
    Which layout manager to learn to use
    Resolution and Swing
    2 panels in south region