这似乎是由MetalButtonUI类的update()方法处理的.以下是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);
}
isToolBarButton()方法只是检查父Container是否是JToolBar,所以我想一个解决方案是始终将JButton添加到JToolBar,然后将工具栏添加到真正的Container.
否则,我想,您需要编写自己的自定义UI并覆盖update()方法.