java frame.setLayout(null) 有什么作用?(frame 是一个 JFrame)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1313974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:06:14  来源:igfitidea点击:

what does frame.setLayout(null)do?(frame is a JFrame)

javaswing

提问by Johanna

I have seen this in a slide but I couldn't get that when and why we use this?

我在幻灯片中看到过这个,但我不明白我们何时以及为什么使用它?

回答by duffymo

null layout means absolute positioning - you have to do all the work in your code. No layout manager to help you out.

null 布局意味着绝对定位 - 您必须在代码中完成所有工作。没有布局管理器可以帮助您。

回答by camickr

Why don't you start by reading the Swing tutorial? There is a section that explains all about Layout Management as well as well what "absolute positioning" is. It also explains when you would use abolute positioning versus using a layout manager.

为什么不先阅读Swing 教程?有一个部分解释了所有关于布局管理以及什么是“绝对定位”。它还解释了何时使用绝对定位与使用布局管理器。

Generally the only time you would use it is when you need to support drag components to a random position.

通常,只有在需要支持将组件拖动到随机位置时才会使用它。

The tutorial also has lots of other basic examples of using Swing components.

本教程还有许多其他使用 Swing 组件的基本示例。