What is the purpose of Layout in SWT applications?

允我心安 提交于 2019-12-02 14:38:08

问题


What is the usage of the Layout in SWT application, since, we can omit it in our applications. What is the benefit of having it?


回答1:


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.



回答2:


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)



回答3:


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.



来源:https://stackoverflow.com/questions/6388184/what-is-the-purpose-of-layout-in-swt-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!