如何在调整窗口大小时重新定位JButton [英] how to reposition JButton on resizing the window

查看:119
本文介绍了如何在调整窗口大小时重新定位JButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的JFrame的底部中间部分保留了一个JButton。现在每当我调整窗口大小时,JButton应该重新定位(在新的中心),具体取决于新调整大小的窗口。任何人都可以告诉我如何实现这一目标。在此先感谢。

I have kept a JButton in the bottom middle part of my JFrame. Now whenever I resize the window the JButton should be repositioned (in the new centre) depending on new resized window. Can anyone tell me how to accomplish this. Thanks in advance.

推荐答案

Swing中的组件根据框架的布局管理器进行渲染。默认布局管理器是BorderLayout,它将框架分为五个逻辑部分:北(上),南(下),东(右),西(左)和中心(中间的一切)。组件默认居中。

Components in Swing are rendered according to the frame's layout manager. The default layout manager is BorderLayout, which divides the frame into five logical parts: North (up), South (down), East (right), West (left) and Center (everything in between). Components are centered by default.

您可以为每个零件创建子框架,并为它们提供类似的布局管理器或完全不同的布局管理器。在你的情况下,你想在主框架的南方位置创建一个新的子框架,并将你的按钮放在其中一个北,中,南位置。

You can create subframes for each part, and give them the a similar layout manager, or a completely different layout manager. in your case you'd want to create a new subframe at the South position of the main frame, and put your button in one of its North, Center or South positions.

希望这有帮助......

Hope this helps...

这篇关于如何在调整窗口大小时重新定位JButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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