Setting the size of a ContentPane (inside of a JFrame)

后端 未结 2 1345
长发绾君心
长发绾君心 2020-12-19 04:55

I want to set the size of a JFrame such that the contentPane is the desired size. JFrame.setSize() doesn\'t take the window decorations into account, so the contentPane is

2条回答
  •  悲&欢浪女
    2020-12-19 05:14

    In Java 5 and later this is the easiest method:

    JFrame frame = new JFrame("Content Pane Size Example");
    frame.getContentPane().setPreferredSize(new Dimension(400, 300));
    frame.pack();
    frame.setVisible(true);
    

    As always the above should be executed in the EDT.

提交回复
热议问题