Setting horizontal and vertical margins

What is the way to set horizontal and vertical margins in a panel? (The same thing we have in html style="margins:30px")

+5
source share
5 answers

Use setBorder(BorderFactory.createEmptyBorder(int top, int left, int bottom, int right); for more help visit this.

+16
source

I don’t know html, so just guess the possible equivalents :-)

  • to set some space between the bounding box of a component and its contents, the property to set is its border
  • LayoutManager ( ). ,
+4

BorderLayout JPanel.

0

, . , Gridbaglayout ,

0

"" JComponents LayoutManagers

BorderLayout (int horizontalGap, int verticalGap)

GridLayout (int rows, int cols, int hgap, int vgap)

1 / multi-user JPanels (with a different LayoutManager for each of the JPanels too)

2 / using How to use GridBagLayout (by multiplying JPanels with different LayoutManegars for each JPanel ...)

3 / use some Custom LayoutManager

0
source

All Articles