This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes JToolBar - setRollover and alignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JToolBar - setRollover and alignment" Watch "JToolBar - setRollover and alignment" New topic
Author

JToolBar - setRollover and alignment

Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Hi there

I have a JToolBar that has several buttons on it. Underneath this toolbar I have a tabbed pane. Now depending on which tabbed pane is selected, certain buttons on the toolbar should be visible. This is taken care of with a method I made called setRelevantButtons(); This removes the unneccesary components and adds the relevant ones.

I have now done this and am adding the setRollover(true). I have set this as the first line in the constructor of my JToolbar, but the borders on the buttons dissapear only after the code in setRelevantButtons() is called. I don't understand why it changes only there as the setRollover is the first line in the constructor outside and completely separate of this method? Btw - I am using the system look and feel and programming for windows machines.

Then lastly, I would like to know if it is possible to have certain buttons on the toolbar on the left (as is default) and certain buttons aligned to the right?

Many kind regards and thanks,
Rachel
[ February 16, 2005: Message edited by: Rachel Swailes ]
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
OK, so I fixed the alignment that I wanted by adding horizontal glue. Who would have guessed that the tool bar is a box layout - really cool! Still not solved the rollover so any help there would be much appreciated.

Thanks,
Rachel
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
Hi Rachel

Can you give a little bit detail about What the code in setRelevantButtons() execute?


Download Java GUI Builder, <a href="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Hi Pat

The code simply adds the buttons to the toolbar that are relevant to the currently selected tab.

I'll post the code...

As you can see it's simply adding and enabling, but I don't understand why the rollover works only after I select any tab myself. In the contructor of the tool bar I have setRollover(true) and after I add the toolbar to the frame, I set the selectedIndex of the tabs to try and activate it.

Is there any other code you would like to see?

Thanks!
Rachel
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
Hi Rachel

I am not sure what cause rollover function works wrong.
In my opinion, sometimes Swing Components might automatically do some operation. Eg:
after removeAll() called, the JToolBar might set Rollover status back to original status. Just guess!

But it doesn't matter, anyway, fortunately you can call setRollover(true) again to solve this problem. it won't be a problem at all.
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
The problem is not with setting the rollover after changing the buttons, the problem is with the first load of the screen and the rollover not activating.

So I'm going to take out all of the rollover code and try with a really simple tool bar and then get that working and implement back into the code.

Cheers,
Rachel
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
I found that by playing with the order of setting the L&F, setting the rollover and setting the screen visible, I have sorted it out.

Thanks again!
Rachel
 
Don't get me started about those stupid light bulbs.
 
subject: JToolBar - setRollover and alignment