Set the JPanel size to fill parent with little margin

imanis_tn picture imanis_tn · Apr 12, 2012 · Viewed 8.2k times · Source

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

Answer

Andrew Thompson picture Andrew Thompson · Apr 12, 2012

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

See TextBubbleBorder for a start.

Obviously you'd need to remove the little v at the bottom, & shove the bottom border further down. The code is not comprehensively tested, and will require further tweaks and fixes. 'Batteries not included'.