#Why this doesn't display image

9 messages · Page 1 of 1 (latest)

opal moss
#
package application;

import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class MainMenu extends JFrame {
    MainMenu() {
        JLabel background;
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setLayout(null);
        setUndecorated(true);
        ImageIcon image = new ImageIcon(this.getClass().getResource("main-bg.png"));
        
        background = new JLabel("", image, JLabel.CENTER);
        background.setBounds(0, 0, JFrame.MAXIMIZED_HORIZ, JFrame.MAXIMIZED_VERT);
        this.add(background);
        setVisible(true);
    }
    
    public static void main(String[] args) {
        new MainMenu();
    }
}
bold lagoonBOT
#

This post has been reserved for your question.

Hey @opal moss! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

mild jetty
#

delete setLayout(null);

opal moss
#

also is there a way to keep image resolution?

#

image displayed was zoomed a bit

mild jetty
#

Im not sure, but I guess you need to set the bounds of JLabel according to the image, not to the window. That's my assumption

opal moss
#

okie i'll try thanks a lot