简体   繁体   English

如何消除按钮周围的蓝色边框? 对于Java GUI

[英]How do i get rid of a blue border surrounding my button? For Java GUI

Because it wont let me add an image - new account 因为它不会让我添加图片-新帐户

怪物

This is utilizing the Java GUI The above image is an image pasted onto a button, I've tried to make the button transparent so that the user can't see it but I can't seem to get rid of this blue border. 这是利用Java GUI的。上面的图像是粘贴到按钮上的图像,我试图使按钮透明,以便用户看不到它,但是我似乎无法摆脱这个蓝色边框。 Code I have so far 我到目前为止的代码

    boss2 = new JButton();    //declared the static button earlier on in the code

    boss2.setSize(300, 300);
    boss2.setLocation(315, 200);
    boss2.setIcon(new ImageIcon("dragon.gif"));
    boss2.setRolloverIcon(new ImageIcon("dragon.gif"));
    boss2.setOpaque(false);
    boss2.setContentAreaFilled(false);
    boss2.setBorder(null);

Is there a way to get rid of the blue border surrounding my image? 有没有办法消除图像周围的蓝色边框?

edit - sorry for the earlier mishap, uploaded the wrong file 编辑-很抱歉,您之前的不幸事故,上传了错误的文件

I would suggest that what you are seeing is the focus rectangle, used to "highlight" the button as having keyboard focus. 我建议您看到的是焦点矩形,用于将按钮“突出显示”为具有键盘焦点。

You can use boss2.setFocusPainted(false); 您可以使用boss2.setFocusPainted(false); to stop it from been painted. 阻止它被绘制。

要没有为JButton绘制边界(假设您正在使用javax.swing.JButton ),您可以简单地执行以下操作:

boss2.setBorderPainted(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM