wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Centering Buttons in a FLow Layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Centering Buttons in a FLow Layout" Watch "Centering Buttons in a FLow Layout" New topic
Author

Centering Buttons in a FLow Layout

Landon Blake
Ranch Hand

Joined: Oct 15, 2004
Posts: 43
I've got two buttons in a JFrame, and I'm using a flow layout. Is there a way to center the buttons in the JFrames content pane vertically. I can set it manually by adjusting the "vGap", but is there another way?

Thanks,

Landon
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / AWT / SWT / JFace forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
add the buttons to a JPanel(gridlayout), then add the JPanel to the frame

JPanel jp = new JPanel(new GridLayout(2,1));
jp.add(btn1);
jp.add(btn2);
frame.add(jp);
Landon Blake
Ranch Hand

Joined: Oct 15, 2004
Posts: 43
Thanks Michael...I'll give that a try. I hadn't thought about using a different layout manager.
 
Consider Paul's rocket mass heater.
 
subject: Centering Buttons in a FLow Layout
 
Similar Threads
layouts
Tricky Question from Mock test
Study Notes from a person who secured 100%.
Positing component
Layout Managers