Reputation: 23256
What is the method to set horizontal and vertical margins in a panel? (The same we have in html style="margins:30px"
)
Upvotes: 18
Views: 44792
Reputation: 23256
setBorder(BorderFactory.createEmptyBorder(int top, int left, int bottom, int right));
And for more details you can read the documentation about BorderFactory
Upvotes: 39
Reputation: 51525
Don't know html, so just guessing on possible equivalents :-)
Upvotes: 6
Reputation: 109813
for create basic "Gap" between JComponents by using LayoutManagers Laying Out Components Within a Container
BorderLayout(int horizontalGap, int verticalGap)
GridLayout(int rows, int cols, int hgap, int vgap)
for most complex GUI you have to
1/ multiplayed JPanels (with different LayoutManager for each of JPanel too)
2/ by using How to Use GridBagLayout (by multiplayed JPanels with different LayoutManegars for each JPanel ...)
3/ use some Custom LayoutManager
Upvotes: 0
Reputation: 4046
That depends highly on the kind of Panel you are using. If this refers to swing you could put a Gridbaglayout on it and specify Insets like in this example
Upvotes: 0