如何制作在调整 JFrame 大小时会调整大小的图像?

How to make images that will re-size when re-sizing a JFrame?

大家好,我在 java 上制作了一款游戏,我希望用户能够调整 window 的大小,而不会弄乱图像。是否有一种特定的方法可用于缩放图像以及 JFrame 和 JFrame 内的组件,在这种情况下是按钮、标签、面板等?顺便提一句。我知道如何缩放其他组件但不知道如何缩放图像

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"));

您可以使用 Darryl 的 Stretch Icon。图标将自动调整大小以填充父组件可用的 space。您将缩放比例设置为成比例或仅归档整个区域。