Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

java - Disable JButton focus border

I have a problem with JButton in Java. Basically, I want to disable the button's border (the button is added to JDesktopPane ).

Here is my code :

 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:

enter image description here

But when my mouse is clicked (not moved around) into the button, there is a "dot" border around the button, like this:

enter image description here

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That is not border. It's focus. You can remove it using:

jButton1.setFocusPainted(false);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...