[英]How do I replace a JPanel with GridLayout with another JPanel with GridLayout in a JFrame?
I am working on a project with GridLayout. 我正在使用GridLayout进行项目。 Currently, I am having trouble replacing a JPanel with GridLayout with another JPanel with GridLayout in my JFrame. 当前,我在用JFrame替换具有GridLayout的JPanel和另一个具有GridLayout的JPanel时遇到了麻烦。 Here is the code. 这是代码。
public JFrame frame = new JFrame();
public JPanel pan = new JPanel();
public void replace() {
frame.remove(pan);
pan = new JPanel();
GridLayout grid = new GridLayout(8,8);
pan.setLayout(grid);
frame.add(pan);
frame.invalidate();
frame.revalidate();
frame.repaint();
}
Much help would be appreciated. 非常感谢您的帮助。 Thanks 谢谢
Does this help? 这有帮助吗?
public JFrame frame = new JFrame();
public JPanel pan = new JPanel();
public void replace() {
frame.remove(pan);
pan = new JPanel();
GridLayout grid = new GridLayout(8,8);
pan.setLayout(grid);
pan.setVisible(true);
frame.add(pan);
frame.invalidate();
frame.revalidate();
frame.repaint();
frame.pack();
frame.setVisible(true);
}
If not, please, explain what is exactly working wrong for you. 如果没有,请说明您到底在做什么错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.