Question

I'm adding a toolbar to my application and currently I'm adding some toggle buttons to the toolbar. I don't like using the default JButton because it is big and clunky (even if I remove the margins). Are there any libraries for easy creation of toolbars and toolbar buttons that look more native? Particularly, I'd like the buttons to look flat unless the user rolls over them or they are selected (like in Eclipse).

thanks, Jeff

Was it helpful?

Solution

Instead of adding the JButton directly to the toolbar, create an Action and add the action instead.

The toolbar will create an appropriate JButton that looks correct.

Additionally, set toolbar.setRollover(true), which will make all the buttons flat, except when the mouse is over it.

Oh, and if you don't want it to be floatable, set toolbar.setFloatable(true).

Those three things, and with a correct L&F, the toolbar usually looks very professional

Generally speaking, we shouldn't be mucking around with button margins ourselves unless we're trying to do something extremely custom.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top