我可以在 swing 中使用单个布局管理器实例吗?
我正在使用 MiGLayout 并且是个怪人,我在想是否可以创建布局的单个实例并将其用于我的所有面板?只是好奇...
I'm using MiGLayout and being the freak i am, i was thinking if it's possible to create a single instance of the layout and use it for all my panels? Just curious...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这完全取决于布局管理器是否保留与布局相关的数据。一般来说,任何接受约束的布局管理器都需要存储这些约束,因此它必须与容器一对一地实例化。
特别参考 MigLayout,看看它存储了多少不适用于多个容器的数据:
That depends entirely on whether the layout manager retains data related to layout. Generally, any layout manager that takes constraints needs to store those, so it must be instantiated one-to-one with the container.
With particular reference to MigLayout, look at how much data it stores that would not be applicable to multiple containers:
某些布局管理器仅适用于一个
Container
(例如BoxLayout
)。我的猜测是,尝试重用相同的布局管理器几乎没有什么好处。Some layout managers will only work with one
Container
(such asBoxLayout
). My guess is that there's little benefit gained by trying to reuse the same layout manager.