0

I just wrote my first JAVA application, and I am wondering what I have to do to make sure the Frame of my application will always be filled with the image.

I do not care if the image is here and there slightly bigger than the frame, but the frame can't be bigger than the image, ever.

I read and googled a lot already, but there was nothing to be found concerning my conditions, I think..

This is my code, hope you can give me some helpful hints:

public AdventureTrails() {

    setTitle("AdventureTrails - Desktop-Application");
    setSize(1000,600);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);

    setLayout(new BorderLayout());
    setContentPane(new JLabel(new ImageIcon(AdventureTrails.class.getResource("src/background.jpg"))));

    setLayout(new BorderLayout());
    initMenu();
    initComponents();

    // Just for refresh :) Not optional!
    setSize(999,599);
    setSize(1000,600);
}
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
maxischl
  • 579
  • 1
  • 11
  • 29
  • 1
    [Example](http://stackoverflow.com/questions/11959758/java-maintaining-aspect-ratio-of-jpanel-background-image/11959928#11959928), [example](http://stackoverflow.com/questions/12876615/how-do-i-resize-images-inside-an-application-when-the-application-window-is-resi/12876799#12876799), [example](http://stackoverflow.com/questions/19648833/java-jpanel-background-not-scaling/19648889#19648889), [example](http://stackoverflow.com/questions/22162398/how-to-set-a-background-picture-in-jpanel/22162430#22162430) – MadProgrammer Jan 11 '17 at 21:35
  • `AdventureTrails.class.getResource("src/background.jpg")` is a bad idea, `src` won't exist once the program is built and packaged, instead you should probably be using `AdventureTrails.class.getResource("background.jpg"))` – MadProgrammer Jan 11 '17 at 21:41
  • thanks man, i hope one of these examples will do :) - and thanks for the hints regarding the image path :) – maxischl Jan 11 '17 at 21:47

0 Answers0