I want to resize JPanel while the program is running, for example, using the menu item. How can I contact him? Or how can I change my program to access live JPanel in the content area?
Edit:
If I make a content area for the playing field, 400x400 at the beginning is the default. But what if I want to declare an option in the menu to resize to 500x500, but without losing all the content already done by the player.
JFrame Class:
package me.test;
import javax.swing.JFrame;
public class Main extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
new Main();
}
public Main() {
setContentPane(new MyJPanel());
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocation(100,50);
setResizable(false);
setVisible(true);
}
}
My JPanel change:
package me.test;
import java.awt.Dimension;
import javax.swing.JPanel;
public class MyJPanel extends JPanel {
public MyJPanel() {
setPreferredSize(new Dimension(400,400));
}
}
source
share