This is apparently handled by the update() method of the MetalButtonUI class. Here is the code from JDK5_07:
public void update(Graphics g, JComponent c) { AbstractButton button = (AbstractButton)c; if ((c.getBackground() instanceof UIResource) && button.isContentAreaFilled() && c.isEnabled()) { ButtonModel model = button.getModel(); if (!MetalUtils.isToolBarButton(c)) { if (!model.isArmed() && !model.isPressed() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } else if (model.isRollover() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } super.update(g, c); }
The isToolBarButton() method simply checks if the parent Container is a JToolBar, so I assume that one solution is to always add the JButton to the JToolBar and then add the toolbar to the real container.
Otherwise, I think you will need to write your own user interface and override the update () method.
source share