Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8203403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:32:36+00:00 2026-06-07T07:32:36+00:00

I’m trying to make a simple GUI using JAVA no image is shown import

  • 0

I’m trying to make a simple GUI using JAVA
no image is shown

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.swing.*;
import javax.imageio.*;

public class EmiloLadderSnack {
    public JFrame frame=new JFrame("EmiloLadderSnack");
    public Image img;
    public Graphics g;
    public EmiloLadderSnack()
    {
        frame.setBounds(0, 0, Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        try
        {
            img= ImageIO.read(new File("/media/01CCE00FA6888D80/Achieve/Eclipse/EmiloLadderSnack/src/photo.jpg"));
            g.drawImage(img, 50, 50, null);
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
    }

    public static void main(String args[])
    {
        new EmiloLadderSnack();
    }
}

please help me to show an image in my simple GUI using JAVA
I’m using Eclipse

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:32:39+00:00Added an answer on June 7, 2026 at 7:32 am

    Hovercraft Full Of Eels is right, as he/she usually is. It really did not look like you tried.

    Look at the tutorials, but I do believe when Hovercraft Full Of Eels says the correct way, hover means as follows.

    Let me explain what I did below. First I created a new class that extended the JFrame. The JFrame is what is suppose to hold all of the components in a window. Then draw on the JPanel so that all of your drawings are contained in a lightweight container. I set the layout with a new layout I just discovered due to StackOverflow which I am very thankful for. The layout is called the MigLayout and it is a third party resource. You have to download it and import it. Please note that you do not have to have the MigLayout, but it is preferable to use due to its ease of use. After I set the Layout Constraint to fill and docked the JPanel in the center I created a new class which extended the JPanel so that I could change the paint method. The @Override lets you, in a way, re create the method for that extended class. As you can see once draw to that one graphics class then you are all set. There is a lot more you should read up on. Read the comments below your post, they suggest fairly good material.

    Anything I get wrong Hovercraft will say below in the comments. So look for that as well.

    Hovers corrections:

    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    
    public class GraphicExample extends JPanel {
       private static final String IMG_FILE_PATH = "/media/01CCE00FA6888D80/" +
            "Achieve/Eclipse/EmiloLadderSnack/src/photo.jpg";
       private BufferedImage img;
    
       public GraphicExample(BufferedImage img) {
          this.img = img;
       }
    
       @Override
       protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          if (img != null) {
             g.drawImage(img, 0, 0, this);
          }
       }
    
       @Override
       public Dimension getPreferredSize() {
          if (img != null) {
             return new Dimension(img.getWidth(), img.getHeight());
          }
          return super.getPreferredSize();
       }
    
       private static void createAndShowGui() {
          try {
             BufferedImage img = ImageIO.read(new File(IMG_FILE_PATH));
             JFrame frame = new JFrame("GraphicExample");
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.getContentPane().add(new GraphicExample(img));
             frame.pack();
             frame.setLocationRelativeTo(null);
             frame.setVisible(true);
    
             // the easy way to display an image -- in a JLabel:
             ImageIcon icon = new ImageIcon(img);
             JLabel label = new JLabel(icon);
             JOptionPane.showMessageDialog(frame, label);
    
          } catch (IOException e) {
             e.printStackTrace();
             System.exit(-1);
          }
    
       }
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                createAndShowGui();
             }
          });
       }
    }
    

    My initial recommendations:

    import java.awt.Color;
    import java.awt.Graphics;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    import net.miginfocom.swing.MigLayout;
    
    public class DrawCircle extends JFrame {
    
        JPanel panel;
    
        public DrawCircle(String title, int width, int height) {
            this.setTitle(title);
            this.setSize(width, height);
            this.setLocationRelativeTo(null); // Center JFrame
            this.setLayout(new MigLayout("fill"));  // Download external jar
            this.panel = new DrawOval();
            this.add(panel, "dock center");  // Link: http://www.miglayout.com/
            this.setVisible(true);
        }
    
        public class DrawOval extends JPanel {
    
                Color color = new Color(1, 1, 1);
    
            public DrawOval() {
    
            }
    
            @Override
            public void paint(Graphics g) {
                g.setColor(color.RED);
                g.fillOval(0, 0, this.getWidth(), this.getHeight());
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.