Java swing removes the focus box around the button text, and draws Wing

Source: Internet
Author: User

Java swing removes the focus box around the button text, and draws Wing

There is nothing left to worry about. I wrote a swing interface. After running it, I can see that when I click the button, a small box containing the text appears in the middle, which indicates that the button gets the focus, I think it's ugly! How can I remove it? The omnipotent 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 below, you can note the sentence for setting attributes to see the effect before and after.

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) {// method stub automatically generated by TODO JFrame jframe = new JFrame ("Demo "); JButton button = new JButton ("JB"); button. addActionListener (new ActionListener () {@ Override public void actionreceivmed (ActionEvent e) {System. out. println ("click JB") ;}}); // remove the focus box button around the button text. setFocusPainted (false); jframe. getContentPane (). add (button); jframe. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); jframe. setBounds (100,100,200,136); jframe. setVisible (true );}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.