6 Replies - 6646 Views - Last Post: 29 February 2012 - 10:15 PM Rate Topic: -----

#1 robgw3   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 138
  • Joined: 23-February 12

How to put space between grid boxes in Grid Layout?

Posted 29 February 2012 - 09:35 PM

How do you put space between grid boxes in a grid layout manager? I managed to get the 12 objects that i need into place, but i need there to be some space between them. Currently they are stuck right up against each other so that six text boxes look like one big one.

I've tried looking through the API and other sites but without knowing what exactly to look for i cant find it.
Is This A Good Question/Topic? 0
  • +

Replies To: How to put space between grid boxes in Grid Layout?

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How to put space between grid boxes in Grid Layout?

Posted 29 February 2012 - 09:39 PM

you can always
new GridLayout(nbRow, nbCol, yPix, xPix);

where xPix and yPix are the number of pixels between each row and column
Was This Post Helpful? 1
  • +
  • -

#3 robgw3   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 138
  • Joined: 23-February 12

Re: How to put space between grid boxes in Grid Layout?

Posted 29 February 2012 - 09:48 PM

Ok thanks, that worked. And figures, as soon as i get an answer i come across the solution in a search.

Anyway if this grid layout is inside a JPanel and the JPanel already has a Title Border on it, is there any way to set like a margin around the edge so that the grids sit a little away from the border?

I know that
dataPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

Can do it but there can only be one border right?
Was This Post Helpful? 0
  • +
  • -

#4 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How to put space between grid boxes in Grid Layout?

Posted 29 February 2012 - 09:52 PM

Make a JPanel p = new JPanel(new GridLayout(1,1));
assign your TitleBorder to it
Make a JPanel p2 = new JPanel(new GridLayout(nbRow, NbCol, 5, 5);
put an EmptyBorder to it
then p.add(p2);

:)
Was This Post Helpful? 1
  • +
  • -

#5 blackcompe   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1159
  • View blog
  • Posts: 2,547
  • Joined: 05-May 05

Re: How to put space between grid boxes in Grid Layout?

Posted 29 February 2012 - 09:53 PM

Quote

Can do it but there can only be one border right?

Try BorderFactory.createCompoundBorder.

This post has been edited by blackcompe: 29 February 2012 - 09:53 PM

Was This Post Helpful? 4
  • +
  • -

#6 robgw3   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 138
  • Joined: 23-February 12

Re: How to put space between grid boxes in Grid Layout?

Posted 29 February 2012 - 10:01 PM

View Postblackcompe, on 29 February 2012 - 09:53 PM, said:

Quote

Can do it but there can only be one border right?

Try BorderFactory.createCompoundBorder.

Great thanks, finally figured out how to get it to work right.
Was This Post Helpful? 0
  • +
  • -

#7 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How to put space between grid boxes in Grid Layout?

Posted 29 February 2012 - 10:15 PM

View Postblackcompe, on 29 February 2012 - 11:53 PM, said:

Quote

Can do it but there can only be one border right?

Try BorderFactory.createCompoundBorder.

Good show, never of that one before :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1