What is GridBagLayout?

Scott Stanchfield

GridBagLayout is a standard layout manager provided with all Java implementations. Layout Managers help you to arrange Graphical User Interfaces that dynamically rearrange their components due to window size changes, as well as changes in fonts or other attributes of components such as displayed text.

You can find details about it at http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html

Note that GridBagLayout is extremely complex and should be avoided when possible. See my article, Effective Layout Management at http://developer.java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/index.html for better ways to create layout managers through nesting simpler layouts. Nearly everything you can do in GridBagLayout can be done by nesting a few simpler layout managers.

Many people say "GridBagLayout isn't that bad -- I learned it". But they miss the point. One of the key issues in software development is that you should write your code so someone else can easily understand it. If you use GridBagLayout, anyone reading your code must know it at least as well as you to understand it. By sticking with simpler layout managers, the layout design is easier to "see" in the code.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact