使用NULL布局时调整框架及其组件的大小 [英] Resizing a frame and its components when using NULL Layout

查看:78
本文介绍了使用NULL布局时调整框架及其组件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用空布局时,如何调整组件的大小?

When using null layout, how to resize components?

我的意思是他们的位置和大小.我知道使用布局管理器不需要解决这个问题. 但是我的要求是在面板中移动组件.所以我应该使用空布局.

I mean their position and size. I know that using layout managers we need not take care of this issue. But my requirement is to move components in the panel. So I ought to use null layout.

如果您有关于寻找新位置以将组件放置在框架尺寸上的想法,请告诉我.

Please let me know if you have ideas regarding finding new locations to place components on resize of the frame.

推荐答案

在没有布局管理器的情况下进行操作教程可能会有所帮助,尽管建议您尽可能使用布局管理器.

Doing Without a Layout Manager tutorial may help, although it is recommended that you use a layout manager, if at all possible.

建议

  1. 使用布局管理器,或
  2. 注册 ComponentListener 并当
  1. Either use a layout manager, or
  2. Register a ComponentListener and manually resize/position components when a resize event occurs.

使用后一种方法可能会花费大量精力,因此强烈建议使用布局管理器.另一个虽然便宜的替代方法(我肯定违反了您的要求),但是是调用

The labor incurred with the latter approach may be enormous, and hence why using a layout manager comes highly recommended. Another, albeit cheap alternative (which I'm sure violates your requirements), is to invoke setResizable(false) on your JFrame.

这篇关于使用NULL布局时调整框架及其组件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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