Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Centering Buttons in a FLow Layout

 
Landon Blake
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / AWT / SWT / JFace forum...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael...I'll give that a try. I hadn't thought about using a different layout manager.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic