Java中的Null布局有什么问题? [英] What's wrong with the Null Layout in Java?

查看:252
本文介绍了Java中的Null布局有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bonjour。

在这个网站上花了无数个小时寻找代码在屏幕上拖动一个组件,我发现答案中有一个奇怪的趋势。

Upon spending countless hours around this site looking for code to drag a component around the screen, I noticed an odd trend growing in the answers.

...每个人都听到空布局的声音。

...being that everyone shudders at the sound of the null layout.

所以我问,每个人都有什么问题呢?我已经编写了不超过三个月的编码,使用Swing不超过一个,并且布局已经轻而易举地使用无限的自定义。为什么这是不好的做法?

So I ask, what's the problem everyone has with it? I've been coding for no more than three months, using Swing for no more than one, and the layout has been a breeze to use with endless customisation possible. Why is it bad practice?

推荐答案

主要问题是试图确定个别平台的复杂性像字体和像素的呈现方式

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.

大部分API已被抽象出来,你永远不应该关心一台PC使用120的DPI并使用DirectX而另一台使用DPI为92并使用OpenGL。

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.

核心Swing API旨在利用此API,因此当组件以某种方式发生变化时如果大小发生变化,则会自动通知所有必需的容器,并且可以根据需要调整组件的整个层次结构。

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.

布局管理器的基本思想是描述同一容器上的组件之间的关系,以及提供有关该容器可能具有多少的信息。这使您可以专注于UI的用户能力,而不是试图花时间尝试更新UI以满足各种可能的硬件和软件组合。

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.

作为一名前VB开发人员(不,我并不感到自豪),我可以向你保证,使用它最令人沮丧的部分是尝试开发可用的动态UI,这些UI在下一台客户端机器上看起来并不好看。

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.

在Swing的所有方面,布局管理是最受欢迎的一个 - 恕我直言

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

这篇关于Java中的Null布局有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆