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

JToolBar - setRollover and alignment

 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rachel

Can you give a little bit detail about What the code in setRelevantButtons() execute?
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic