*
The moose likes Swing / AWT / SWT and the fly likes Button alignment  in a JToolbar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Button alignment  in a JToolbar" Watch "Button alignment  in a JToolbar" New topic
Author

Button alignment in a JToolbar

Indika Hewage
Ranch Hand

Joined: May 18, 2004
Posts: 35
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

Joined: Aug 26, 2005
Posts: 824
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();
}
}


Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
Indika Hewage
Ranch Hand

Joined: May 18, 2004
Posts: 35
Thanks Sunil for the example.
 
 
subject: Button alignment in a JToolbar