• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which layout to use?

 
Sudharshan Reddy Ch
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 4 buttons in my applicaiton, i have to arrange them in vertical. Through which layout i can do it? Please send me some sample code regarding.

Thanks.
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new java.awt.GridLayout(4,1)
 
Sudharshan Reddy Ch
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but using that the whole form will be occupied with the buttons. I want those buttons to display in center of my form.
 
Sudharshan Reddy Ch
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got that, i used BoxLayout like this

panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

and while adding the buttons

panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
panel.add(b1);
panel.add(Box.createRigidArea(new Dimension(0,5)));
panel.add(b2);
panel.add(Box.createRigidArea(new Dimension(0,5)));
panel.add(b3);
panel.add(Box.createRigidArea(new Dimension(0,5)));
panel.add(b4);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!