Search code examples
javaswingjpaneldynamic-sizing

Set the JPanel size to fill parent with little margin


I have two Jpanel (JpanelLeft and JpanelLeftContent) how can i make the JpanelLeftContent fill parent size with a little margin on the left an right side. i have tried different layout and tried to modify the hgap and vgap values, but none of them give me a good result.

  JPanel JpanelLeft = new JPanel();
  JPanel JpanelLeftContent = new JPanel();
  JpanelLeft.add(JpanelLeftContent);

And if possible how can i make the JpanelLeftContent look like a rounded rectangle as shown in the picture.

enter image description here


Solution

  • Take a look at how Borders work. Especially
    BorderFactory.createEmptyBorder(int top, int left, int bottom, int right) might be helpfull.