1

Hi guys I made a game on java and I want the user to be able to resize the window without the images getting all messed up. Is there a specific method to use for scaling the images along with the JFrame and the components inside the JFrame whic in this case are buttons, labels, panels, etc? BTW. I know how to scale other components but not the images

ImageIcon MainLogo = new ImageIcon (getClass().getResource("/SudokuIcons/MainLogo.png"));
ImageIcon MainLogoMenu2 = new ImageIcon (getClass().getResource("/SudokuIcons/MainLogoMenu2.png"));
ImageIcon MainLogoMenu3 = new ImageIcon (getClass().getResource("/SudokuIcons/MainLogoMenu3.png"));
ImageIcon playLogo = new ImageIcon (getClass().getResource("/SudokuIcons/PlayLogo.png"));
ImageIcon OptionsLogo = new ImageIcon (getClass().getResource("/SudokuIcons/OptionsLogo.png"));
ImageIcon HelpLogo = new ImageIcon (getClass().getResource("/SudokuIcons/HelpLogo2.png"));
ImageIcon ExitLogo = new ImageIcon (getClass().getResource("/SudokuIcons/ExitLogo.png"));
ImageIcon StartGame = new ImageIcon (getClass().getResource("/SudokuIcons/StartGame.png"));
ImageIcon ChooseDifficulty = new ImageIcon (getClass().getResource("/SudokuIcons/ChooseDifficulty.png"));
ImageIcon ChooseDifficultyMenu2 = new ImageIcon (getClass().getResource("/SudokuIcons/ChooseDifficultyMenu2.png"));
ImageIcon GoBackIcon = new ImageIcon (getClass().getResource("/SudokuIcons/GoBack.png"));
ImageIcon GoBack2Icon = new ImageIcon (getClass().getResource("/SudokuIcons/GoBack2.png"));
ImageIcon GoBack3Icon = new ImageIcon (getClass().getResource("/SudokuIcons/GoBack3.png"));
ImageIcon EasyIcon = new ImageIcon (getClass().getResource("/SudokuIcons/EasySelected1.png"));
ImageIcon MediumIcon = new ImageIcon (getClass().getResource("/SudokuIcons/MediumSelected1.png"));
ImageIcon HardIcon = new ImageIcon (getClass().getResource("/SudokuIcons/HardSelected1.png"));
ImageIcon EasyIconSelected = new ImageIcon (getClass().getResource("/SudokuIcons/EasySelected1.png"));
Eudy Contreras
  • 396
  • 3
  • 10
  • What did you try? Please show the code – Bahramdun Adil Dec 20 '15 at 11:35
  • Im using ImageIcons, Please also know Im a biginner who started programming 2 and a half months ago. My images wont resize as I resize the window, even If I use a base of 4k resolutions. they wont scale down – Eudy Contreras Dec 20 '15 at 11:46
  • Post an [MCVE](http://stackoverflow.com/help/mcve). Be sure to copy-paste your code to a *new project* and make sure it compiles and runs before posting it here. – user1803551 Dec 20 '15 at 11:51
  • 2
    Possible duplicate of [How to fit Image size to JFrame Size?](http://stackoverflow.com/questions/13038411/how-to-fit-image-size-to-jframe-size) – MC10 Dec 20 '15 at 11:51
  • my code runs well, the game runs well, the problem is that if I resize the frame or the window used. the images do not scale together with the window – Eudy Contreras Dec 20 '15 at 12:28

1 Answers1

3

You can use Darryl's Stretch Icon. The Icon will automatically resize to fill the space available to the parent component. You set the scaling to be proportional or just file the entire area.

camickr
  • 321,443
  • 19
  • 166
  • 288