aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to put spaces between two buttons in Grid Layout? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to put spaces between two buttons in Grid Layout? " Watch "How to put spaces between two buttons in Grid Layout? " New topic
Author

How to put spaces between two buttons in Grid Layout?

Yuta Lolap
Ranch Hand

Joined: Jun 03, 2012
Posts: 83

Hello,

I am working with grid layout for the first time. How do i put a space between two buttons here?
Please help me! It would solve a lot of issues!


I am designing a login form. And i wanted to put some space between the username button and the usernametxt. Posting a code of just buttons. Please do let me know.


Thanks in advance,
Yuta Lolap.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 156
win.setLayout(new GridLayout(3, 2, 10, 10));, more in API
Yuta Lolap
Ranch Hand

Joined: Jun 03, 2012
Posts: 83

wat does 3,2,10,10 mean? What if i have to apply more space then which nos do i change?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4462
    
    8

Did you follow the link to the API that M Korbel provided? That explains what the parameters mean.
Yuta Lolap
Ranch Hand

Joined: Jun 03, 2012
Posts: 83

Got it!
public GridLayout(int rows,
int cols,
int hgap,
int vgap)

But one more question the Hgap and Vgap , whats the measuring unit?
Yuta Lolap
Ranch Hand

Joined: Jun 03, 2012
Posts: 83

How do i fix the size of the button? When i re-size the frame to a larger resolution the button size also increases.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 156
- GridLayout to take PreferredSize from JComponents is most largest / widest and the appply this PreferredSize for rest of elements

- in GridLayout all JComponents have got the same size on the screen
Yuta Lolap
Ranch Hand

Joined: Jun 03, 2012
Posts: 83

What you said is a little confusing. Do you mean to say that i cant specify fixed size at all?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

You can specify a fixed size, and the buttons would all be that size. But you do that by specifying the size of the whole component. If that's still confusing, have a look at the API documentation for GridLayout (<== follow that link). It has pictures.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to put spaces between two buttons in Grid Layout?