Java Pack 不调整大小 [英] Java Pack No Resize

查看:44
本文介绍了Java Pack 不调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习 Java 并且有以下问题:

i am learning Java at the moment and have the following question:

我将控件添加到 JFrame,然后在显示之前进行 pack().

i am adding my controls to JFrame and then pack() before displaying.

这会运行应用程序,一切都非常好.

this runs the application and all is very nice.

我想知道有没有办法阻止用户调整应用程序窗口的大小?

i was wondering is there a way to stop the user from resizing the application window?

还有没有办法让 JLabel 中的图像随着用户更改应用程序窗口而展开?

also is there a way to for the image in JLabel to expand as the user changes the application window?

目前我认为:

    constraints.fill = GridBagConstraints.BOTH;
    constraints.anchor = GridBagConstraints.CENTER;

它只使图像居中,我希望能够扩展/缩小图像.

and it only centers the image, i would like to be able to expand/shrink the image.

谢谢.

推荐答案

我想知道有没有办法停下来用户调整应用程序大小窗户?

i was wondering is there a way to stop the user from resizing the application window?

如果您根本不想让用户调整窗口大小,那么您可以这样做

If you don't want to allow users to resize your window at all then you can do

frame.setResizable (false);


我不确定此技术是否可以与 pack() 同时成功使用.你当然应该尝试,但我记得如果你这样做会出现一个问题:

I'm not sure that this technique can be successfully used at the same time with pack(). You should certainly try, but I remember there was an issue that if you do:

frame.setResizable (false);
pack();

然后 pack() 根本没有做它应该做的,如果你做了:

then pack() simply doesn't do what it should and if you do:

pack();
frame.setResizable(false);

然后你的窗口变得更窄,然后只有pack().当然,可以找到一些解决方法(或者甚至可能只是我的糟糕经历).

then you window becomes a little more narrow then after only pack(). Of course, some workaround can be found (or maybe even it's just my bad experience).

这篇关于Java Pack 不调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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