Results 1 to 4 of 4
  1. #1
    DerekRaimann is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default How do you set insets on a panel?

    I have a very simple program using Swing. It creates a JFrame, and within that frame I create a panel using BorderLayout. The panel contains a ComboBox and a Label that changes depending on the selected item in the combo box. I was wondering, can I create insets for the panel without using a grid bag layout and setting constraints? Thank you for taking the time to read this and for any help you can give me!

    -Derek Raimann

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You can set the JPanel's border via the setBorder method and use an EmptyBorder with appropriate parameters.

    e.g.,

    Java Code:
    myPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));

  3. #3
    DerekRaimann is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default

    You hit the nail on the head, thank you so much! :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Add panel to parent panel
    By LovJava in forum AWT / Swing
    Replies: 10
    Last Post: 09-02-2010, 08:43 PM
  2. Panel in a panel?
    By pahiker in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2010, 11:42 AM
  3. Adding a panel to a panel
    By rclausing in forum New To Java
    Replies: 7
    Last Post: 02-02-2010, 05:56 AM
  4. weird insets change in JFrame subclass
    By sowilo in forum AWT / Swing
    Replies: 4
    Last Post: 11-18-2009, 12:27 AM
  5. [SOLVED] How to set insets for JComboBox.......?
    By prabhurangan in forum AWT / Swing
    Replies: 3
    Last Post: 07-01-2008, 06:25 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •