What is the purpose of Layout in SWT applications?
What is the usage of the Layout in SWT application, since, we can omit it in our applications. What is开发者_StackOverflow社区 the benefit of having it?
Automatic layout requires less of your time than manual/absolute layout.
First, it's less effort overall to specify a layout with desired properties than an absolute layout. You can quickly add, move or remove items in an automatic layout, without tweaking the absolute positions of all other items.
Next, these factors sometimes make automatic layout necessary:
- Localization: Translated labels can be longer or shorter, requiring layout adjustments.
- Resizing dialogs and windows frequently requires adjusting the layout.
- As @Daniel first notes below, controls may have different sizes on different platforms.
- Fonts may differ among platforms and users.
- Dynamic data.
- Dynamic visibility.
Controls don't have the same size on every platform. Since SWT uses native controls the sizes differ regarding to:
- System settings (Font size, Border sizes)
- Operating System Version (Windows 95 vs. Windows XP vs. Windows 7, all different)
- Operating System at all (Windows, MacOS, Linux)
- Window Manager (Windows default, GTK, Motiv, some strange userprovided Windows Window Managers like ThemeXP Pro)
How components in a container relate to each other and to the container itself can become complex. The layout manager encapsulates these rules for you so you can avoid dealing with them. When the container is resized for instance, how do you want your components to change to accomodate the new size? If you had to code it all it would be difficult to get it done right.
精彩评论