【问题标题】:How to make images that will re-size when re-sizing a JFrame? [closed]如何在重新调整 JFrame 大小时制作将重新调整大小的图像? [关闭]
【发布时间】:2016-03-26 15:08:57
【问题描述】:

大家好,我在 java 上制作了一个游戏,我希望用户能够调整窗口大小而不会弄乱图像。是否有一种特定的方法可用于缩放图像以及 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"));

【问题讨论】:

  • 你尝试了什么?请出示代码
  • 我正在使用 ImageIcons,还请知道我是 2 个半月前开始编程的资深人士。当我调整窗口大小时,我的图像不会调整大小,即使我使用 4k 分辨率的基础。他们不会缩小规模
  • 发布MCVE。请务必将您的代码复制粘贴到新项目,并确保在将其发布到此处之前编译并运行。
  • 我的代码运行良好,游戏运行良好,问题是如果我调整框架或使用的窗口的大小。图像不随窗口一起缩放

标签: java eclipse image swing resize


【解决方案1】:

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

【讨论】:

  • 听起来和我要找的完全一样,非常感谢。我会试试看=)
猜你喜欢
  • 2012-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-29
  • 2013-04-23
  • 2018-06-15
  • 2022-11-19
  • 2011-10-04
相关资源
最近更新 更多