set alignment of JToolBar

I made an application where put a jtoolbar on top. It is in the north of a borderlayout. My only problem is that the alignment of the toolbar is always center, no matter where i put it. I want to set the alignment left, so that the jtoolbar is on the left.

i've put the jtoolbar in a jpanel:

add(toolbarpanel, BorderLayout.NORTH);

it placed the panel in the north like i told you in the beginning, but how to set the alignment of the toolbar?
i've used methods like setAlignmentX() but didn't work. please help..
2008Asked:
Who is Participating?
 
membershConnect With a Mentor Commented:
If jpanel's layout is flowlayout, then set its alignment by using setAlignment(FlowLayout.LEFT). If it is BorderLayout, then add it to BorderLayout.WEST.  

Similar workarounds are available for other layout's too...
0
 
CEHJCommented:
A quick and dirty way would be:

toolbarpanel.setLayout(null);
toolbarpanel.add(yourToolbar);
add(toolbarpanel, BorderLayout.NORTH);
0
 
objectsCommented:
> i've put the jtoolbar in a jpanel

Instead add your toolbar directly.
0
 
2008Author Commented:
I've tried all this.
CEHJ: if i put your code, the toolbar disappear.

objects: i've already done that, doesn't work.

membersh: that doesn't work either.
0
 
CEHJCommented:
>>CEHJ: if i put your code, the toolbar disappear.

Did you set the size of the toolbar to something appropriate before you added it?
0
All Courses

From novice to tech pro — start learning today.