![]() Note: You can download this article's complete source code from Resources. In so doing, I incorporated much of GridBagLayout's alignment power. Thinking I could improve upon GridLayout, I wrote SGLayout as a complete replacement. In one example, a simple password panel, Dorohonceanu incorporates a series of labeled text fields into a grid and shows how to improve the panel's appearance by decreasing the label column's width relative to that of the text field column. In this Java Tip, I describe a layout manager, SGLayout, with similar flexibility and direct control over margins, gaps between rows and columns, and fine control over how to locate a component within the grids. In " Java Tip 121: Flex Your Grid Layout" ( JavaWorld, December 2001), Bogdan Dorohonceanu describes a GridLayout subclass that avoids the requirement that a grid's elements possess the same dimensions. ![]() With that in mind, a better way to get similar results must exist. ![]() On this basis, GridBagLayout gets particularly poor marks. Personally, I follow the "least surprise" principle when I look at layout managers: If you are surprised at a layout manager's behavior, it probably was designed poorly. GridBagLayout, in particular, is very powerful, but many developers find it difficult and nonintuitive. Of these, BorderLayout and FlowLayout generally prove useful, but developers often start running into difficulties when coding more complex layouts. A good layout manager proves essential for creating a good graphical user interface (GUI), but many beginner developers find the standard Java layout managers difficult to master.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |