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