GridBag布局还是绝对定位? [英] GridBag Layout or Absolute Positioning?
问题描述
我正在处理一段代码,其中几个imageIcons将与其他几个imageIcons重叠. 前景中的图像图标将保持不变,而背景中的图像图标将变为不同的图像图标
I'm working on a piece of code where several imageIcons will overlap several other imageIcons. imageIcons in the foreground will stay the same while imageIcons in the background will change to different imageIcons
我通常在布局上没有最好的运气.例如,当我调整框架大小时,组件将移动.另外,当我添加一个对象然后添加另一个对象时,第二个对象将推"另一个对象正确(或在设计特殊布局以放置下一个组件的任何地方.
I don't usually have the best luck with layouts. Components will move when I adjust the frame size, for instance. Also, when I add one object and then add another object, the second object will "push" the other object right (or wherever the particular layout is designed to put the next component.
Oracle网站强调了尽可能使用布局管理器的重要性(出于大小调整的原因).这是我在GridBag布局上使用Aboslute定位的情况之一吗?
Oracle's website stresses the importance to use a layout manager whenever possible (for sizing/resizing reasons). Would this be one of those cases where I would use Aboslute Positioning over the GridBag layout?
推荐答案
如果容器中容纳的组件的大小不受容器大小或字体,外观和语言变化的影响,则绝对定位可能会导致虽然没有布局管理器也是可以的,但您应该尽可能使用布局管理器.布局管理器使调整与外观依赖的组件外观,不同的字体大小,容器的变化大小以及不同的语言环境变得更加容易.[根据Oracle.com]
If a container holds components whose size is not affected by the container's size or by font, look-and-feel, or language changes, then absolute positioning might make sense.Although it is possible to do without a layout manager, you should use a layout manager if at all possible. A layout manager makes it easier to adjust to look-and-feel-dependent component appearances, to different font sizes, to a container's changing size, and to different locales.[According to Oracle.com]
查看此链接,也许可以为您提供帮助.
Look at this link, may be this can help you.
http://www.leepoint.net/notes-java/GUI/layouts/60gridbaglayout.html
这篇关于GridBag布局还是绝对定位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!