Making a JPanel manually resizable(使 JPanel 手动调整大小)
问题描述
我有一个 JFrame 与 BorderLayout 作为布局管理器.
I have a JFrame with BorderLayout as the layout manager.
在南边,我有一个JPanel,我希望这个JPanel的大小可以由用户调整,即用户可以点击边缘边框并将其向上拖动以使其变大.
In the south border, I have a JPanel, I want this JPanel's size to be adjustable by the user, i.e. the user can click on the edge of the border and drag it up to make it larger.
你有什么方法知道我可以做到这一点吗?
Is there any way you know that I can do this?
推荐答案
为了使框架中的面板可以单独调整大小,您需要将它们添加到 JSplitPane.
In order to make panels in a frame individually resizable you need to add them onto a JSplitPane.
不要将它放在框架的南部,而是将 JSplitPane 放在中心.拆分窗格将使拆分中的底部面板看起来像是在南方,而拆分中的顶部面板将位于框架的中心.
Instead of putting it in the South portion of the Frame, put the JSplitPane in the Center. The split pane will make the bottom panel in the split seem like it is in the South, and the top panel in the split will be in the Center of the frame.
确保使用 setOrientation(JSplitPane.VERTICAL_SPLIT) 设置两个面板的方向.
Make sure you set the orientation of the two panels with setOrientation(JSplitPane.VERTICAL_SPLIT ).
然后,您可以调整窗格中的面板大小.
Then, you can resize the panels that are in the pane.
这篇关于使 JPanel 手动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使 JPanel 手动调整大小
基础教程推荐
- Maven:无效的目标版本:10 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
