ImageIcon by JLabel example with absolute positioning

寵の児 提交于 2019-12-14 00:06:09

问题


I have seen a lot of example code but none that specifically shows me how to display an ImageIcon through the use of a JLabel on a JFrame without using a layout manager. I am repeatedly told that absolute positioning is a hassle and less efficient than a layout manager but I'd prefer complete control over where my elements are going. A full scale example class (with no extra things added) of a JLabel that will display an image on a JFrame with absolute positioning would be much appreciated, thank you


回答1:


The image I need has to move around the screen

An important piece of information missing in the original question. I don't have a problem using a null layout for this.

I wanted to move around with arrow keys on the screen?

And don't use a KeyListener for this. Instead you should be using Key Bindings.

See the KeyboardAnimation.java code found in Motion Using the Keyboard for one solution to this problem.



来源:https://stackoverflow.com/questions/29439797/imageicon-by-jlabel-example-with-absolute-positioning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!