• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Layout Managers & Proper Spacing

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I have a simple GridBagLayout setup with three columns. In the top center column, I have a label with the title. In the second, third, and fourth rows, I have a label in the first column and a textarea/textfield in the second two columns. Finally, on the bottom, I have a button in each column.

My problem is that the spacing between the label and the textarea/textfields is great, but the spacing between the first column and the left side of the entire frame, as well as teh last column and the right side of the frame is just... too thin?

I'm trying to think of the best way to phrase the question...

How can I add spacing ONLY between the left edge of the frame and the left side of the first column, as well as the right edge of the frame and the right side of the last column? Is there any method for doing this?

I can provide pictures if necessary.
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that GridBagLayout applied to a JPanel which is inside the JFrame, and you want that space outside the JPanel? In that case a custom border for the panel might be the way to go. Or perhaps modify the Insets for the panel?
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I can provide pictures if necessary.



No, we never want pictures. A picture doesn't show use what your code is like. Instead we rely on a SSCCE, which is used to simplify the problem because we also don't want to look at hundreds of lines of code to try and understand what you are doing.

To expand on Paul's suggestion, you should be able to use an EmptyBorder. If you don't know about Borders then read the section from the Swing tutorial on How to Use Borders.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Is that GridBagLayout applied to a JPanel which is inside the JFrame, and you want that space outside the JPanel? In that case a custom border for the panel might be the way to go. Or perhaps modify the Insets for the panel?



GridBagLayout is applied to a JPanel which is inside the JFrame, yes. I want the space that is not outside the JPanel (this would be between the JPanel and the JFrame, which I have using a border like you mentioned), but the space that is just inside the JPanel on the outside. Does that make sense?

If you know HTML/CSS, the best way to phrase it is by using the box model as an example. I am using a mock "margin" by using a border on the JPanel, but how do I create a "padding" for the Panel itself?

Also Rob, the SSCCE link is great, thank you. I didn't know the protocol on all of that. When I meant a picture, though, it is simply meant to show the space I am looking to expand, but I understand when code is necessary.

Also, I've looked at the border examples and they help, and I have used the borders as mentioned above.

Thanks for the help so far guys!
 
Paul Clapham
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the difference, in practice, between "padding" and just inserting another border between the JPanel and its border? There is such a thing as a CompoundBorder which you could use to do that.
 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shortly after i posted, I discovered Compound bordered. They worked great!
 
reply
    Bookmark Topic Watch Topic
  • New Topic