17.8 LAYOUT MANAGEMENT IN GUI PROGRAMS


17.8 LAYOUT MANAGEMENT IN GUI PROGRAMS

One of the first things a GUI designer has to think about is where to place a GUI component in a window with regard to the window frame and with regard to the placement of the other components. This issue is more complex than it seems at first thought.

Let's say we want to place a few buttons in a top-level window. One's first thought would be to place the buttons at certain predesignated locations. But that would seem like a poor GUI design if the choice of the fixed locations for the buttons caused the window to look appalling when it is resized by a user.

Another option, it would seem, would be to place the buttons at locations relative to the dimensions of a window. So if a window was reduced to, say, half its width and half its height, the coordinates of the button locations would be reduced to half their original values. This is certainly better than the first solution, but it still suffers from a shortcoming. As the locations of the buttons change proportionately to the resized dimensions of a window, if the button sizes remain fixed, we could end up with overlapping buttons if the window size became small enough. Resizing of the top-level window with fixed-sized buttons could also lead to a poor-looking window in which the spaces between the buttons would acquire forms not appropriate for displaying the information that needed to be displayed there. On the other hand, if we allow the sizes of the buttons to also change as a window is resized, a button may stop looking like a button.

While there are no perfect solutions to the difficulties listed above, many of the problems can be alleviated by using a layout manager supplied with a GUI toolkit. As an example of the smarts incorporated in modern layout managers, some of them can "float" the components inside a container. By "float" we mean that the layout manager will automatically resize, reposition, or, in some cases, even rearrange the components as a window is resized so that the layout of the components maintains a certain visual form. To illustrate this idea better, one of the layout managers in Java arranges the components symmetrically along a row. But if upon resizing, the width of the window becomes too small to accommodate all the components in that row, the layout manager automatically places one or more components symmetrically in the next row.

Layout managers often accept user-supplied recommendations regarding the default, the minimum, and the maximum sizes to use for the components. This can prevent a graphical application from looking too ghastly if the user chooses an "unnatural" size for the top-level window.

In the subsections that follow, we will present the main classes for layout management in Java-based AWT/Swing, in C++-based Qt, and in C-based GNOME/GTK+. We will illustrate each class with a simple example. But note that more complex layouts can be produced by nesting the layouts. For example, a particular cell in a grid-like positioning of the GUI components could be a holder for a horizontal arrangement of other components, and so on.




Programming With Objects[c] A Comparative Presentation of Object-Oriented Programming With C++ and Java
Programming with Objects: A Comparative Presentation of Object Oriented Programming with C++ and Java
ISBN: 0471268526
EAN: 2147483647
Year: 2005
Pages: 273
Authors: Avinash Kak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net