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.
To make a JPanel appear rounded, you need to make your own class that extends JPanel, override paintComponent and draw the panel as an ellipse Javadoc here This will create a customized object which is an JPanel.
When you specify the size of your ellipse, you want to get the Y and X values from the parent panel (since you will be adding your ellipse ontop of another panel) and then subtract the number of pixels you desire from the X-axis. This could be achived by passing those values to the "ellipse panel" constructor.
Do try this code example :
Here is the output of the same :
Take a look at how
Border
s work. EspeciallyBorderFactory.createEmptyBorder(int top, int left, int bottom, int right)
might be helpfull.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'.