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

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

问题描述

卓悦.

在这个网站上花费无数个小时寻找代码以在屏幕上拖动组件后,我注意到答案中有一个奇怪的趋势.

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,而另一台使用 92 的 DPI 并使用 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 中的空布局有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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