• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using JToolBar  RSS feed

 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guy's !!!
How can a JToolBar instance in appearance be made to look similar to "Windows" toolbar(one used in Internet Explorer,Windows Explorer,MS-Office).It appears flat on-sight but elevated on "MouseOver" and appears depressed on "Click".
Pls Suggest.
Thanks a lot.
 
Daniel Searson
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this would work (hasnt been tested) but you could use this initially:

You can get the button reference from the JToolBar (check the docs).
Then create a mouse listener for your button that changes the border on mouse enters/exits:

The above class is assuming that it is an inner class within your JButton class. You could do this in a few different ways, though.
Hope that helps.
- Daniel
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
The way I have done this is when I create the button, i set border painted to false like so:
mybutton.setBorderPainted(false);
Then, I use a mouseListener as Daniel suggests (I extend mouseListener on the encompassing JFrame or JToolBar class, and then define the methods mouseExited() mouseEntered().
Then, when the event source is mybutton, do this in mouseEntered()...
mybutton.setBorderPainted(true);
and this in mouseExited...
mybutton.setBorderPainted(false);

Seems to work ok when I have done this a couple of times in different apps. Haven't done the depressed look 'on click' because it doesn't seem worth the bother to me
cheers, Ben.
 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Daniel !!!
 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben !!!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!