如何删除单击 JButton 时出现的蓝色框

How to remove the blue box that appears when i click JButton

当我点击按钮时,图像的空白部分看起来是蓝色的。有什么办法吗?

        left.setPressedIcon(l1);
        left.setOpaque(false);
        left.setFocusPainted(false);
        left.setBackground(new Color(0,0,0,0));
        left.setBorderPainted(false);
        left.setBounds(-15, 400, 100, 200);
left.setBackground(new Color(0,0,0,0));

不要尝试使用透明色。 Swing 无法正确绘制透明颜色。参见:Backgrounds With Transparency.

在任何情况下都不需要,因为您正在使用

 left.setOpaque( false );

When i click Button, the blank part of the image looks blue

尝试:

left.setContentAreaFilled( false );

还有:

left.setBounds(-15, 400, 100, 200);

不要使用 setBounds(...) 和空布局。 Swing 旨在与布局管理器一起使用。