What's wrong with the Null Layout in Java? [duplicate]

浪子不回头ぞ 提交于 2019-11-27 09:51:05

The major problem is the complexities involved in trying to make determination about individual platforms with regards to things like fonts and how pixels may be rendered

Even two systems, running the same OS can generate different output due to different hardware drivers and rendering pipelines.

Much of the API has been abstracted in such away that you should never care that one PC is using a DPI of 120 and using DirectX and another is using a DPI of 92 and using OpenGL.

Layout managers remove the developer from the responsibility of having to calculate the size a component (and its child components) at a particular moment in time as well as calculating the relationship between these components and does it in a standardised way.

The core Swing API has been designed to utilise this API, so when a component changes in some way that would represent a change in the size, all the required containers are notified automatically and the entire hierarchy of components can be adjusted as required.

The basic idea of a layout manager is to describe the relation between components on the same container as well as providing information about how much that container might like to have. This allows you to focus on the user-ability follow of the UI rather then trying to spend time trying to update the UI to meet all various possible combinations of hardware and software.

As a former VB developer (no, I'm not proud if it), I can assure you, the most frustrating part of working with it was trying to develop usable, dynamic UIs that didn't look crap on the next clients machine.

Of all the aspects of Swing, the layout management is one of the most welcomed - IMHO

Because it's not a layout. All you are doing is using a GUI editor to place your components in absolute locations. And resizing your window or running your code under a different monitor resolution will look terrible.

looking for code to drag a component around the screen

That is a different requirement. By definition when you drag a component around the screen you can't program the location.

Having said that a layout manager does more then just set the location of a component. Check out Drag Layout for a layout that you can still use in this situation.

For other situations a layout manager (or combination of nested layout managers) if the better solution for designing effective GUI's.

You will loose some points for GUI for using it, because it's hard to maintain, more code, less flexible,... Adding an extra button will lead to a lot of recalculation you have to do.

How i see it : http://leepoint.net/notes-java/GUI/layouts/nulllayout.html

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