There is no specialized image component provided in Swing (which is sad in my opinion). So, there are a few options:
- 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);
where JImageComponent is a self created class that extendsJComponent
that overrides thepaintComponent()
method to draw the image.
Related Posts:
- Setting background images in JFrame
- How do I draw a triangle?
- Java: Rotating Images
- How do I draw a triangle?
- Java GUI: about getContentPane( ) method and content
- How to add an image to a JPanel?
- How to programmatically close a JFrame
- Adding JPanel to JFrame
- How change the color arrowIcon to JMenu when it is selected
- Getting a HeadlessException: No X11 DISPLAY variable was set
- error upon assigning Layout: BoxLayout can’t be shared
- Resizing image in Java
- imageio.IIOException: Can’t read input file
- JOptionPane YES NO OPTION
- Java: Difference between the setPreferredSize() and setSize() methods in components
- What does “AL lib: alc_cleanup: 1 device not closed” mean?
- How to center the text in a JLabel?
- How to repaint a JPanel after have drawn on it?
- Implementing an actionlistener to a JTextField
- How to Set JPanel’s Width and Height?
- addMouseListener for a JPanel
- Swing/Java: How to use the getText and setText string properly
- What does super.paintComponent(g) do?
- How to Set the Background Color of a JButton on the Mac OS
- Change the size of a JTextField inside a JBorderLayout
- Java Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
- Popup Message boxes
- Exception in thread “AWT-EventQueue-0”?
- make a JLabel wrap it’s text by setting a max width
- Keylistener not working for JPanel
- setMnemonic() and call a method by pressing the key
- the getSource() and getActionCommand()
- Java Error Exception in thread “AWT-EventQueue-0” java.lang.StackOverflowError
- How does addNotify() and requestFocus() work in Java with JPanel?
- DTO and DAO concepts and MVC
- How to Retrieve value from JTextField in Java Swing?
- Setting background color for a JFrame
- What does .pack() do?
- Java Swing revalidate() vs repaint()
- How does paintComponent work?
- How can I set size of a button?
- Java Swing setting JPanel Size
- How to draw a circle with given X and Y coordinates as the middle spot of the circle?
- set background color: Android
- set background color: Android
- JOptionPane Yes or No window
- Problem with gif with transparent background
- Search for words with telephone numbers from 2-3-4 tree
- What is the reason behind “non-static method cannot be referenced from a static context”? [duplicate]
- Java string to date conversion
- Creating a “logical exclusive or” operator in Java
- Cannot make a static reference to the non-static method fxn(int) from the type Two [duplicate]
- What is IllegalStateException?
- Long vs Integer, long vs int, what to use and when?
- Java Using Nodes with LinkedList
- When is the @JsonProperty property used and what is it used for?
- Java: using switch statement with enum under subclass
- Java way to check if a string is palindrome
- No String-argument constructor/factory method to deserialize from String value (”)
- Where can i get BigClip? [closed]
- What is the /= operator in Java?
- How can I list the available Cipher algorithms?
- ADK vs JDK vs SDK difference?
- round up to 2 decimal places in java?
- com.sun.jdi.InvocationException occurred invoking method
- How can I check whether an array is null / empty?
- How to solve javax.net.ssl.SSLHandshakeException Error?
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘demoRestController’
- What causes java.lang.IncompatibleClassChangeError?
- Add an object to an Array of a custom class
- IO Error: The Network Adapter could not establish the connection
- How to create a directory in Java?
- Converting from Integer, to BigInteger
- Get a resource using getResource()
- Java comparing generic types
- java – How to handle array:Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 3
- How to print the data in byte array as characters?
- An established connection was aborted by the software in your host machine tomcat jackson
- Generate a random double in a range
- How to open a new tab using Selenium WebDriver in Java?
- Selenium Webdriver: Element Not Visible Exception
- Whitespace Matching Regex – Java
- Unreachable code in eclipse
- Android Emulator: Unfortunately App has stopped
- Can we execute a java program without a main() method? [duplicate]
- How to really read text file from classpath in Java
- Java command not found on Linux
- Selenium using Java – The path to the driver executable must be set by the webdriver.gecko.driver system property
- How to break out or exit a method in Java?
- Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/JDBC_DBO]]
- Append a single character to a string or char array in java?
- Preventing a Java class from being instantiated and inherited
- Collision Detection between two images in Java
- String is immutable. What exactly is the meaning?
- How do I autoindent in Netbeans?
- What is an attribute in Java?
- KeyPressed event in java
- MessageBodyWriter not found for media type=application/json
- Conversion from Long to Double in Java
- Failed to find Java VM