[英]Positioning a label using swing in java
I have been using jFrame to build a GUI. 我一直在使用jFrame来构建GUI。 I had to insert images in the GUI, for which i inserted a label and put the image as an icon for the label.
我必须在GUI中插入图像,为此我插入了标签并将图像作为标签的图标。 Now, i have to find out the position of the image in terms of the x and y co-ordinates and i am unable to do that.
现在,我必须根据x和y坐标找出图像的位置,而我无法做到这一点。 I have used
我用过
setLocaction(x,y);
but it still doesn't seem to work. 但它似乎仍然不起作用。 I even disabled the layout manager by using
我什至通过使用禁用了布局管理器
setLayout(null);
What is the possible solution for this problem? 该问题的可能解决方案是什么?
Edit 编辑
Basically i am creating a Solar system GUI using Swing, so the positions of the planets are to be set by me. 基本上,我是使用Swing创建Solar System GUI的,所以行星的位置应由我来设置。 I being new to java, there is being some difficulty in implementing the layouts.
我是Java的新手,在实现布局方面有些困难。
This isn't a layout issue at all, but a drawing and possibly an animation issue. 这根本不是布局问题,而是图形甚至是动画问题。 If this were my project, I'd
如果这是我的项目,我会
paintComponent
method. paintComponent
方法内部绘制我的星球精灵。 HashMap<Plant, Image>
. HashMap<Plant, Image>
将BufferedImage与每个Planet关联。 使用null布局时,应在标签上使用setSize
和setLocation
方法,以使图像在框架内正确可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.