在Java JFrame中显示图像 [英] Display image in Java JFrame

查看:188
本文介绍了在Java JFrame中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java JFrame中以特定坐标显示图像的最佳方法是什么?

What's the best way to display an image at specific coordinates in a java JFrame?

我知道有很多方法可以做到这一点,我只需要知道显示我计划在框架周围移动的图像的最佳方式!

I know there are a number of ways to do this, I just need to know the best way to display an image that I am planning on moving around the frame!

推荐答案

我建议将其添加为ImageIcon:

I would suggest adding it as an ImageIcon:

ImageIcon image = new ImageIcon("image.jpeg");
add(image);






编辑(如何添加添加特定坐标) :


EDIT (How to add it add specific coordinates):

首先是一个注释,通常(99%的情况)不鼓励自己定位JComponents。使用LayoutManager为你定位它们,并处理调整大小。

我会告诉你如何自己定位:

First a note, usually (99% of the cases) it is NOT encouraged to position JComponents yourself. Use a LayoutManager to position them for you, and handle the resizing.
I will tell you how to position it yourself though:


  • 将LayoutManager设置为 null setLayout(null)

  • ImageIcon 设置为特定坐标: image.setLocation(x,y)

  • Set your LayoutManager to null: setLayout(null).
  • set your ImageIcon to specific coordinates: image.setLocation(x, y).

这篇关于在Java JFrame中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆