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

标签 java eclipse image swing resize

<分区>

大家好,我用 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"));

最佳答案

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

关于java - 如何制作在调整 JFrame 大小时会调整大小的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34380496/

相关文章:

java - 如何使用 Java 在 Google Cloud Storage 中插入 pdf 文件

Java ImageView 字符串作为 src

image - MATLAB imagesc 命令不适用于非均匀间隔的 y 轴值

java - 从 EditText 中检索文本

java - 如何在 Google App Engine 中检测 HTTP 响应大小

java.awt.Image getWidth 和 getHeight 方法不能正常工作?

java - m2eclipse 依赖版本不是最新的

java - SVG 到 Java 的 Path2d 解析器

ios - 带图像的水平滚动 uicollectionView

html - 图片不适合手机屏幕