File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Adding padding to GUI components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding padding to GUI components" Watch "Adding padding to GUI components" New topic

Adding padding to GUI components

Matthew Taylor

Joined: Jun 13, 2004
Posts: 110
I'm using a border layout, and each cell except SOUTH in the layout contains a JPanel. Each JPanel contains a few components. All I would like to do is add some padding to the NORTH and SOUTH JPanels and keep them centered....

Or, I want to take this:

to this:

How can I add padding either to the JPanels in the NORTH and SOUTH cells, or to the BorderLayout cells?

Of course that really wasn't code, but it was the only way I could find to format it correctly.
[ October 18, 2004: Message edited by: Matthew Taylor ]

Grails Consultant
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
You can pad every cell in a BorderLayout by using the constructor
new BorderLayout(5,5) where 5 is the px of padding you want on every cell.

You can also pad components individually by giving them an empty border (or compound border if you need the line).

Matthew Taylor

Joined: Jun 13, 2004
Posts: 110
I should have known. Thanks, the EmptyBorder did what I wanted.
I agree. Here's the link:
subject: Adding padding to GUI components
jQuery in Action, 3rd edition