gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 09:57:31 24 4
gpt4 key购买 nike

我尝试通过更改 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 类的实例 - 现在可以工作。

/**
* 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);
}

关于java - 如何去除弹出窗口和工具提示周围的灰色阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53923487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com