Java Swing removes the focus frame around the button text

Source: Internet
Author: User

Nothing to do, write a swing interface, after running to see when the click button, the middle of the text will appear a text around the small box, which is the button to get the focus of the logo, I feel a word: ugly! How to get rid of it? Almighty degree Niang tell me, set the button of the setfocuspainted to false, I tried a bit, sure enough, the following will code to share to everyone, you can set the attributes of that sentence, to see the effect before and after.

Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;ImportJavax.swing.JButton;ImportJavax.swing.JFrame; Public classSwingdemo { Public Static voidMain (string[] args) {//TODO Auto-generated method stubsJFrame JFrame =NewJFrame ("Demo"); JButton Button=NewJButton ("JB"); Button.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {System.out.println ("Click JB");        }        }); //Remove the focus frame around the button textButton.setfocuspainted (false);        Jframe.getcontentpane (). Add (button);                Jframe.setdefaultcloseoperation (Jframe.exit_on_close); Jframe.setbounds (100, 100, 200, 136); Jframe.setvisible (true); }}

Java Swing removes the focus frame around the button text

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.