使JPanel手动调整大小 [英] Making a JPanel manually resizable

查看:638
本文介绍了使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手动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆