java swing remove focus box around button text
I had nothing to do, so I wrote a swing interface. After running it, I saw that when the button is clicked, a small box will appear in the middle text that just surrounds the text. This is a sign that the button has gained focus. I think one word: ugly! How to remove it? The almighty Du Niang told me to set the setFocusPainted of the button to false. I tried it and it was ok. I will share the code with you below. You can comment out the sentence about setting the attributes to see the before and after effects.
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo { public static void main(String[] args) { // TODO 自动生成的方法存根 JFrame jframe = new JFrame("Demo"); JButton button = new JButton("JB"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("click JB"); } }); //去掉按钮文字周围的焦点框 button.setFocusPainted(false); jframe.getContentPane().add(button); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setBounds(100, 100, 200, 136); jframe.setVisible(true); } }
It’s not enough for people who work in IT to just look at it. If you do more, you will gain something.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics









