My code does not work:
JFrame frame = new JFrame("mull");
mull panel = new mull();
// add panel to the center of window
frame.getContentPane().add("Center", panel);
frame.setSize(500, 300); // << not working!!!
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack(); // give a suitable size to window automatically
frame.setVisible(true); // make window visible
I am getting very small window. How to fix it?
解决方案
Well, you are using both frame.setSize() and frame.pack().
You should use one of them at one time.
Using setSize() you can give the size of frame you want but if you use pack(), it will automatically change the size of the frames according to the size of components in it. It will not consider the size you have mentioned earlier.
Try removing frame.pack() from your code or putting it before setting size and then run it.