search
Home类库下载java类库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.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!