[英]Resize JPanel in a JFrame
I am having problem in making my Java Application to resize itself when the screen size changes. 屏幕尺寸发生变化时,我在使Java应用程序自行调整大小时遇到问题。
My ui is as follows : 我的用户界面如下:
I have a JPanel which consist of a few images and buttons. 我有一个JPanel,其中包含一些图像和按钮。
I have a GridLyout which i add 9 JPanel mentioned above into the GridLayout. 我有一个GridLyout,我将上面提到的9个JPanel添加到GridLayout中。
The problem is the JPanel object seem too big to fit into the layout. 问题在于JPanel对象似乎太大,无法放入布局中。 I have read that using a layout manager will resolve the problem however it didnt work in my case.
我已经读过使用布局管理器可以解决问题,但是在我的情况下却没有用。
I have designed the ui using netbean GUI builder and had not make any changes to the properties. 我已经使用Netbean GUI构建器设计了ui,并且没有对属性进行任何更改。 I
一世
Any suggestion ? 有什么建议吗? Thank you so much.
非常感谢。
Windowed View 视窗检视
Full Screen View 全萤幕检视
I would like to achieve all 9 JPanel to show irregardless of window size. 我想实现所有9个JPanel的显示,无论窗口大小如何。 I have tried using layout recommended in some post.
我已经尝试使用某些帖子中推荐的布局。
Adding Jpanel 添加Jpanel
for (int x = 0; x < 9; x++) {
UserUI tmp = new User_UI("User is " + x);
mainPanel.add(tmp);
validate();
}
You may want to try this: 您可能要尝试以下操作:
If you're adding the panel to the JFrame, it may not size correctly, try setting the panel as the JFrames content pane. 如果要将面板添加到JFrame,则可能无法正确调整大小,请尝试将面板设置为JFrames内容窗格。 Instead of:
代替:
frame.add(mainPanel)
Do: 做:
frame.setContentPane((JComponent)mainPanel);
I hope this helps :) 我希望这有帮助 :)
ALSO Did you add the layout manager to the JPanel or to the JFrame? 还您是否将布局管理器添加到JPanel或JFrame? if you set it on the JFrame, just add a layout manager to your JPanel instead!
如果您在JFrame上进行设置,只需将布局管理器添加到JPanel中即可!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.