About style settings for JButton in Java (some of the functions we should know)

Source: Internet
Author: User

11, setting the size of the JButton2 --Because Jbuten is a small device type, the general setsize can not be awakened to the size of the setting, so generally we use3Button.setpreferredsize (NewDimension (30,30));4      //(30,30) is the size of the button you want to set52, transparent settings for JButton6 --the button is set to transparent so that it does not block back background7Button.setcontentareafilled (false);83, set the border of the button to remove the JButton9 --If sometimes your button does not need a border because the border is beautiful or because you need to click the Previous button to render the normal imageTen after clicking, you can use this method to remove the border OneButton.setborderpainted (false); A4, add icons to JButton settings -——//instantiate an Icon object -ImageIcon image =NewImageIcon (Icons[i]); the      //instantiates a button object and displays a picture on the Settings button -JButton button =NewJButton (image); - --or -Button.seticon (NewImageIcon (GetClass (). GetResource ("Qq.png"))); +      //Qq.png is the picture you want to add -5, make the button change with the pattern on the button +Butten.setmargin (NewInsets (0,0,0,0)); A6, set up a convex button, and many other swing can also use this method at Butten.setborder (Borderfactory.createraisedbevelborder ()); -7, set up a concave button, and many other swing can use this method - Button.setborder (Borderfactory.createloweredbevelborder ()); -8, set the foreground and background color of the button -button. SetFont (NewJava.awt.Font ("XXFarEastFont-Xingkai", 1, 15)); - Button.setbackground (color.green); in9, 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.