How to make a JPanel inside a JFrame fill the whole window?

后端 未结 4 422
深忆病人
深忆病人 2021-01-14 01:43

In the below example, how can I get the JPanel to take up all of the JFrame? I set the preferred size to 800x420 but it only actually fills 792x391.

import j         


        
4条回答
  •  -上瘾入骨i
    2021-01-14 02:13

    This took me forever to figure out but its actually the simplest code ever. Just create a parent panel and pass GridLayout then add your child panel like this.

    JPanel parentPanel= new JPanel(new GridLyout());
    JPanel childPanel= new JPanel();
    parentPanel.add(childPanel);
    

提交回复
热议问题