Home 类库下载 java类库 java swing remove focus box around button text

java swing remove focus box around button text

Oct 14, 2016 pm 01:35 PM

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);
    }

}
Copy after login

It’s not enough for people who work in IT to just look at it. If you do more, you will gain something.

Statement of this Website
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

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

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1235
24