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?
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?
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.
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.
Joined: Oct 02, 2009
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.