Common JButton settings in Java, javajbutton

Source: Internet
Author: User

Common JButton settings in Java, javajbutton
1. Set the JButton size. setPreferredSize (new Dimension (30, 30); // (30, 30) is the size of the button you want to set 2. Set the button transparent to the JButton. setContentAreaFilled (false); 3. Set the button for removing the border of the JButton. setBorderPainted (false); 4. Add an icon to the JButton. instantiate an icon object ImageIcon image = new ImageIcon (icons [I]) and instantiate a button object, and the set button shows the image JButton = new JButton (image); -- or button. setIcon (new ImageIcon (getClass (). getResource ("qq.png"); // qq.png is the image you want to add. 5. Let the button change with the pattern on the button. setMargin (new Insets (,); 6. Set the highlighted button. Many other swing methods can also be butten. setBorder (BorderFactory. createRaisedBevelBorder (); 7. You can use this method to set the concave button. setBorder (BorderFactory. createLoweredBevelBorder (); 8. Set the foreground color and background color of the button. setFont (new java. awt. font (" 文 ", 1, 15); button. setBackground (Color. green); 9. Change the style of the button UIManager. setLookAndFeel ("com. sun. java. swing. plaf. windows. windowsLookAndFeel ");

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.