Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display image in 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!

like image 520
Ben Hagel Avatar asked May 29 '12 20:05

Ben Hagel


People also ask

How do I add an image to a JFrame?

Adding an Image in Java JFrame Firstly, we create a JLabel using the Java Swing library. Secondly, we use the setIcon() method to add and display the image. This method defines to display the icon. However, if the value of the icon is null, nothing is displayed.

How do I display a JFrame?

A JFrame is like a Window with border, title, and buttons. We can implement most of the java swing applications using JFrame. By default, a JFrame can be displayed at the top-left position of a screen. We can display the center position of JFrame using the setLocationRelativeTo() method of Window class.


1 Answers

Using an ImageIcon with a JLabel is the easiest way. You can actually add this to a level in JFrame's JLayeredPane that is above or below the contentPane depending on your requirements

like image 182
ControlAltDel Avatar answered Oct 11 '22 12:10

ControlAltDel