Jframe with background image

public class PanelImagen extends javax.swing.JPanel { public PanelImagen(){ this.setSize(400,280); } @Override public void paintComponent (Graphics g){ Dimension tamanio = getSize(); ImageIcon imagenFondo = new ImageIcon(getClass().getResource("./fondoc4.jpg")); g.drawImage(imagenFondo.getImage(),0,0,tamanio.width, tamanio.height, null); setOpaque(false); super.paintComponent(g); } } PanelImagen p = new PanelImagen(); p.setBorder(new EmptyBorder(5, 5, 5, 5)); p.setLayout(new BorderLayout(0, 0)); setContentPane(p);
This code let add an image throw jpanel inside jframe

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.