Set JPanel size to fill the parent by a small margin

I have two Jpanel ( JpanelLeft and JpanelLeftContent ), how can I make JpanelLeftContent fill the parent size with a small margin from left to right. I tried a different layout and tried to change the values ​​of hgap and vgap, but none of them gave 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

+1
source share
4 answers
+3
source

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

To get started, launch TextBubbleBorder .

Qrlyr.png

Obviously, you will need to remove the small v below and push the lower border down. The code is not subjected to comprehensive testing and will require additional settings and corrections. "Batteries not included."

+4
source

Try this sample code:

 import java.awt.*; import javax.swing.*; public class InsetTesting extends JFrame { private void createAndDisplayGUI() { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setLocationByPlatform(true); JPanel contentPane = new JPanel(); contentPane.setOpaque(true); contentPane.setBorder(BorderFactory.createLineBorder( Color.DARK_GRAY.darker(), 5, true)); contentPane.setBackground(Color.WHITE); add(contentPane, BorderLayout.CENTER); pack(); setVisible(true); } public Insets getInsets() { return (new Insets(30, 20, 10, 20)); } public Dimension getPreferredSize() { return (new Dimension(200, 400)); } public static void main(String\u005B\u005D args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new InsetTesting().createAndDisplayGUI(); } }); } } 

Here is the result of the same:

INSETS

+3
source

To make JPanel rounded, you need to create your own class that extends JPanel, overrides paintComponent, and draws the panel as a Javadoc ellipse here. This will create a custom object that is 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 add your ellipse on top of the other panel), and then subtract the number of pixels you want from the X axis. This can be achieved by passing these values ​​to the ellipse panel constructor.

+2
source

All Articles