Java Form background map + Set button style

Source: Internet
Author: User

This method should be cumbersome, because the background map is placed on the second level of the form, if the form content layer has a lot of panels, you have to set the transparency. Words don't say much, on the code:

1 ImportJava.awt.Color;2 Importjava.awt.Dimension;3 Importjava.awt.FlowLayout;4 ImportJava.awt.event.WindowAdapter;5 Importjava.awt.event.WindowEvent;6 7 ImportJavax.swing.ImageIcon;8 ImportJavax.swing.JButton;9 ImportJavax.swing.JFrame;Ten ImportJavax.swing.JLabel; One ImportJavax.swing.JPanel; A  -  Public classBackgroundextendsJFrame { -      the      -      Public Static voidMain (string[] args) { -         NewBackground (); -     } +      - Background () { +          This. Settitle ("Background"); A          This. setlayout (NewFlowLayout ()); atJButton JB =NewJButton ("Test"); -          This. Add (JB); -          -         //Place a background map -ImageIcon background =NewImageIcon (Background.class. getClassLoader (). GetResource ("Images/img.jpg")); -JLabel Bklabel =NewJLabel (background); inBklabel.setbounds (0, 0, Background.geticonwidth (), Background.geticonheight ()); -          This. SetSize (Background.geticonwidth (), Background.geticonheight ()); to          This. Getlayeredpane (). Add (Bklabel,NewInteger (Integer.min_value)); +JPanel Ctpanel = (JPanel) This. Getcontentpane (); -Ctpanel.setopaque (false); the          *         //Set Button style $Jb.setpreferredsize (NewDimension (100,40));//Set SizePanax NotoginsengJb.setbackground (NewColor (118,238,0));//Set Background color -Jb.setforeground (Color.White);//Set foreground color theJb.setfont (NewJava.awt.Font ("Microsoft italics", 1, 20));//Set Font style +          A          This. Addwindowlistener (NewWindowadapter () { the              Public voidwindowclosing (windowevent arg0) { +System.exit (0); -             }             $         }); $          This. setvisible (true); -     } -  the}

Picture placement: (In the Java Project created) src > New > Folder > Folder name:images > Finish, dye back paste the picture into the images

Java Form background map + Set button style

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.