GIF as wallpaper JFrame Java

0

I'm trying to place a GIF as wallpaper, the problem is that the GIF does not occupy the entire screen. How can I fix it so that the GIF occupies the whole screen so that even if the window size is changed, it keeps occupying everything?

This is my code:

public class ViewInicio extends JFrame {
private JLabel fondo;
public ViewInicio() {
setLayout(new BorderLayout()); setSize(1500,900); setTitle("View Inicio"); setMinimumSize(new Dimension(700, 700)); setIconImage(new ImageIcon(getClass().getResource("/resources/icon.png")).getImage()); setDefaultCloseOperation(EXIT_ON_CLOSE);
fondo = new JLabel(); fondo.setIcon(new ImageIcon(getClass().getResource("/hundirlaflotilla/resources/fondo.gif"))); getContentPane().add(fondo);
setVisible(true); } }
    
asked by Ivan Garcia Ballesteros 20.12.2017 в 17:28
source

2 answers

0

You must take into account the dimensions of the image GIF , and that of your Pane in the Jframe . When you place the image as a background, look for the property MAXIMUN SIZE

    
answered by 29.11.2018 в 17:13
0

so that the size of the background image is modified adapting to the window, you must assign the background image with the appropriate scale in the event that controls the change in size of the JFrame, it would be like this:

addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent ev) {
        Image imgFondo=new ImageIcon(getClass().getResource("/imagenes/fondo.gif")).getImage();
        fondo.setIcon(new ImageIcon(imgFondo.getScaledInstance(ev.getComponent().getWidth(), ev.getComponent().getHeight(), Image.SCALE_DEFAULT)));
    }
});

I hope it has been helpful.

    
answered by 21.12.2017 в 20:15