Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


set alignment of JToolBar

Posted on 2003-02-27
Medium Priority
Last Modified: 2011-04-14
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..
Question by:2008
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Expert Comment

ID: 8037930
A quick and dirty way would be:

add(toolbarpanel, BorderLayout.NORTH);
LVL 92

Expert Comment

ID: 8037992
> i've put the jtoolbar in a jpanel

Instead add your toolbar directly.

Accepted Solution

membersh earned 300 total points
ID: 8038993
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...

Author Comment

ID: 8040871
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.
LVL 86

Expert Comment

ID: 8040874
>>CEHJ: if i put your code, the toolbar disappear.

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

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question