如何去除弹出窗口和工具提示周围的灰色阴影?

How to remove grey shadow around popups and tooltips?

我尝试通过更改 LookAndFeel 和为组件创建自定义工具提示来移除弹出窗口和工具提示周围的阴影边框 - 但这些都不起作用。

我使用的一种方法是 复合边框 具有指定的外部和内部边框。

LaF 中的第一个:

Border border = BorderFactory.createLineBorder(Color.BLUE, 1);
Border margin = new EmptyBorder(10,10,10,10);
UIManager.getDefaults().put("ToolTip.border",new CompoundBorder(border, margin))

第二个通过覆盖特定组件中的 createToolTip():

@Override
public JToolTip createToolTip() {
    JToolTip tip = super.createToolTip();
    tip.setBackground(Colors.BLUE_TINT_LIGHT);
    tip.setForeground(Colors.TEXT_DARK_STEEL);
    Border border = BorderFactory.createLineBorder(Color.BLUE, 1);
    Border margin = new EmptyBorder(10,10,10,10);
    tip.setBorder(new CompoundBorder(border, margin));
    return tip;
}

在 LaF 部分有 ShadowPopupBorder 的初始化,用于工具提示、弹出窗口和模式对话框边框。我修改了 paintBorder 并添加了一个额外的检查组件对象是否是 JTooltip 的实例 class - 现在有效。

/**
 * Paints the border for the specified component with the specified
 * position and size.
 */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    // fake drop shadow effect in case of heavy weight popups
    JComponent popup = (JComponent) c;
    Image hShadowBg = (Image) popup.getClientProperty(ShadowPopupFactory.PROP_HORIZONTAL_BACKGROUND);
    if (hShadowBg != null) {
        g.drawImage(hShadowBg, x, y + height - 5, c);
    }
    Image vShadowBg = (Image) popup.getClientProperty(ShadowPopupFactory.PROP_VERTICAL_BACKGROUND);
    if (vShadowBg != null) {
        g.drawImage(vShadowBg, x + width - 5, y, c);
    }

    // draw drop shadow
    g.drawImage(shadow, x +  5, y + height - 5, x + 10, y + height, 0, 6, 5, 11, null, c);
    g.drawImage(shadow, x + 10, y + height - 5, x + width - 5, y + height, 5, 6, 6, 11, null, c);
    g.drawImage(shadow, x + width - 5, y + 5, x + width, y + 10, 6, 0, 11, 5, null, c);
    g.drawImage(shadow, x + width - 5, y + 10, x + width, y + height - 5, 6, 5, 11, 6, null, c);
    g.drawImage(shadow, x + width - 5, y + height - 5, x + width, y + height, 6, 6, 11, 11, null, c);
}