问题描述
我在Java中遇到JButton的问题。基本上,我想禁用按钮的边框(按钮添加到JDesktopPane)。
I have a problem with JButton in Java. Basically, I want to disable the button's border (the button is added to JDesktopPane ).
这是我的代码:
JButton j = new JButton("BUTTON");
j.setIcon(icon1); //icon1 : icon//
j.setFocusable(true);
j.setContentAreaFilled(false);
j.setBounds(90, 20, 130, 30);
dtp.add(j); //dtp : JDesktopPane//
它可以让边框像这张图片一样消失:
It could let the border disappear like in this image:
但当我点击鼠标(未移动)到按钮时,按钮周围有一个点边框,如下所示:
But when my mouse is clicked (not moved around) into the button, there is a "dot" border around the button, like this:
那么,怎么可能我设置了按钮,这样当我不在按钮区域移动鼠标时,它仍然像第一个图像一样设置,但是当我移动鼠标时,按钮周围有一个方形(浅蓝色背景)?
So, how could I set the button so that when I don't move the mouse around the button area, it's still set like the first image, but when I move the mouse around, there's a square around the button (with a light-blue background)?
推荐答案
这不是边界。这是焦点。你可以使用以下方法删除它:
That is not border. It's focus. You can remove it using:
jButton1.setFocusPainted(false);
这篇关于禁用JButton焦点边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!