[英]Set size of a Jframe in the Jpanel program?
In the JPanel program, I wrote this: 在JPanel程序中,我这样写:
String size = JOptionPane.showInputDialog("What frame length?");
int s = Integer.parseInt(size);
and I use the s variable in the body of the code. 我在代码主体中使用s变量。
The problem is, I need to use the variable to also set the size of JFrame, and I don't know how to transfer the variable to that program.. Could I set the size inside the JPanel program? 问题是,我需要使用变量来设置JFrame的大小,并且我不知道如何将变量传输到该程序。我可以在JPanel程序中设置大小吗?
EDIT: For JPanel, I created a Buffered Image and put a bunch of graphics on it. 编辑:对于JPanel,我创建了一个缓冲图像,并在其上放了一堆图形。 For the Jframe, all I did was I set the location and open the content pane for JPanel.
对于Jframe,我要做的就是设置位置并打开JPanel的内容窗格。
use SwingUtilities.getWindowAncestor 使用SwingUtilities.getWindowAncestor
javax.swing.SwingUtilities.getWindowAncestor(yourpanel).setSize(
new Dimension(size,size)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.