Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Button alignment in a JToolbar

 
Indika Hewage
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have 4 buttons in a toolbar. All these buttons appears on the left side of the toolbar. I need it to locate these buttons into the middle of the toolbar. Is it possible to do add these buttons into the middle of the toolbar?

Thanks.
Indika
 
Sunil Kumar Gupta
Ranch Hand
Posts: 824
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this

import javax.swing.*;
import java.awt.*;

public class Test extends JFrame{
JToolBar tb=new JToolBar();
public Test(){
tb.setLayout(new FlowLayout(FlowLayout.CENTER));
tb.add(new JButton("Hello"));
tb.add(new JButton("Middle"));
tb.add(new JButton("Test"));
getContentPane().add("North", tb);
setSize(200,200);
setVisible(true);
}
public static void main(String arg[]){
new Test();
}
}
 
Indika Hewage
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sunil for the example.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic