Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to control TitledBorder insets / margin / buffer / space?

843806Feb 23 2009 — edited Feb 24 2009
I'm trying to remove some space on my GUI. Here's a simple example, with a couple buttons in a JPanel with a TitledBorder.

Is there any way to decrease the space between the buttons and the border (especially the top one)?

I'm pretty sure it has something to do with the TitledBorder's insets, but I don't see any obvious way to decrease it.
I don't understand what the getBorderInsets() method does, or what I should pass to it.

Thanks!
import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Test
{
   public static void main (final String[] args)
   {
      JPanel panel = new JPanel();
      panel.setBorder (BorderFactory.createTitledBorder ("Title"));
      panel.add (new JButton ("Button 1"));
      panel.add (new JButton ("Button 2"));
      
      JFrame frame = new JFrame();
      frame.add (panel, BorderLayout.CENTER);
      frame.pack();
      frame.setVisible (true);
   }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2009
Added on Feb 23 2009
2 comments
1,750 views