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
341 views
in Technique[技术] by (71.8m points)

java - Swing: remove focus border from dialogues' buttons

I wonder how can I remove this grey border from buttons in dialogues? enter image description here

For simple JButtons I found a solution - just use button.setFocusPainted(false); But is there a simple way to perform the same for all buttons in all dialogues? I tried to look through UIManager properties, but it seems that there are no suitable parameters there. enter image description here

Thanks in advance!

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)
  • from JButtons API you can to use JButton.setFocusable() and with JButton.setBorderPainted(false);

  • from UIManager have to override key (valid for whole JVM instance)

.

UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put("Button.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
  • I'd to suggest to change Color with transparency (4th paramater in a.m. code) to another more decent Color, otherwise you can't to see focus for any of `JButtons

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
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

56.9k users

...