How to set specific window (frame) size in java swing?

前端 未结 3 1703
情话喂你
情话喂你 2020-12-16 10:33

My code does not work:

JFrame frame = new JFrame(\"mull\");

mull panel = new mull();

// add panel to the center of window
frame.getContentPane().add(\"Cent         


        
3条回答
  •  执笔经年
    2020-12-16 11:06

    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.

提交回复
热议问题