File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding padding to GUI components" Watch "Adding padding to GUI components" New topic
Author

Adding padding to GUI components

Matthew Taylor
Rancher

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
http://dangertree.net
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).
myComp.setBorder(BorderFactory.createEmptyBorder(top,left,bottom,right));

Cheers,
Rachel
Matthew Taylor
Rancher

Joined: Jun 13, 2004
Posts: 110
I should have known. Thanks, the EmptyBorder did what I wanted.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding padding to GUI components