Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
355 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...