调整框架大小后如何调整网格大小?
我想知道以下内容:我有一个 MainWindow 组件(其中包含一个框架(JFrame))和几个其他 JPanel。其中一个 JPanel,假设 gridPanel 使用 gridLayout 作为 LayoutManager。现在我的问题是我想在调整窗口大小后进行调整(设置行的大小/设置列的大小)。有人可以告诉我如何实现在调整框架大小后可以触发的操作,因为我不熟悉所涉及的听众。
它应该是在最“标准”的编码实践上完成的。感谢您的回复和解答!
I was wondering the following: I have a MainWindow component (which contains a frame (JFrame)) and several other JPanels. Where one JPanel, let's say gridPanel uses the gridLayout as LayoutManager. Now my problem is that I want to adjust (set the size of rows / set the size of columns) after the window has been resized. Can someone tell me how I can achieve actions that can be triggered after resizing the frame as I am not familiar with the listeners involved.
It should be the done on the most "standard" coding practices. Thank you for your response and answers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望网格“填满”一个容器,或者填满 JFrame,那么关键是使用正确的布局管理器来保存使用 GridLayout 的容器。例如,如果将使用 GridLayout 的容器添加到另一个使用 FlowLayout 的容器,则使用 GridLayout 的容器在其容纳容器的大小发生变化时也不会更改大小。但是,如果将使用 GridLayout 的容器添加到另一个使用 BorderLayout 的容器及其 BorderLayout.CENTER 位置,则使用 GridLayout 的容器将随着使用 BorderLayout 的父容器调整大小而调整大小。
示例:
此外,如果这没有帮助,那么您可能希望详细说明您的问题和发布代码,最好是 SSCCE 。
If you want your grid to "fill up" a container, or fill up the JFrame, then key is to use proper layout managers to hold the GridLayout-using container. For instance if you add the GridLayout-using container to another container that uses FlowLayout, then the GridLayout-using container will not change size if its holding container changes size. However if you add the GridLayout-using container to another container that uses BorderLayout and to its BorderLayout.CENTER position, then the GridLayout-using container will resize as the BorderLayout-using parent container resizes.
Example:
Also, if this is not helpful, then you may wish to elaborate more on your problem and post code, preferably an SSCCE.
也许 Wrap Layout 就是您正在寻找的。
Maybe the Wrap Layout is what you are looking for.