问题描述
所以我使用Eclipse与Windows建设者。我只是想知道是否有反正我可以导入将在JFrame中显示出来,我可以很容易地走动,重新大小,而不是设置的位置和大小,并绘制它的形象。
So I am using Eclipse with Windows builder. I was just wondering if there was anyway I can import an image that'll show up on the JFrame that I can easily move around and re-size instead of setting the location and size and drawing it.
推荐答案
有在Swing没有提供专门的图像成分(这是悲哀在我看来)。因此,有几个选项:
There is no specialized image component provided in Swing (which is sad in my opinion). So, there are a few options:
- 作为@Reimeus说:使用一个JLabel带图标
-
创建窗口建设者一个JPanel,这将重新present图像的位置。使用$ C $的几行自己的自定义图像组件,然后添加到在JPanel c您将永远不会有改变。他们应该是这样的:
- As @Reimeus said: Use a JLabel with an icon.
Create in the window builder a JPanel, that will represent the location of the image. Then add your own custom image component to the JPanel using a few lines of code you will never have to change. They should look like this:
JImageComponent ic = new JImageComponent(myImageGoesHere);
imagePanel.add(ic);
其中JImageComponent是覆盖的paintComponent()
方法来绘制图像的自我创建的类扩展的JComponent
where JImageComponent is a self created class that extends JComponent
that overrides the paintComponent()
method to draw the image.
这篇关于将图片添加到JFrame中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!