Image Help!

+1 Landon Luman · October 5, 2014
So I've been trying to be able to display images in Java, but I just can't seem to do it! I don't know if it is a library problem, or a code bug. But please help me if you can guys...


Post a Reply


Oldest  Newest  Rating
0 Developer John · October 7, 2014
Sorry, I forgot to also state that once you use that code, you can use them for things like JComboBox. Here is the message again but more simplified for you to understand:
private static String[] filename = {"pic1.jpg", "pic2.jpg", "pic3.jpg"};
//Here I create an array that stores the picture names

    private Icon[] pics = {new ImageIcon(getClass().getResource(filename[0])), new ImageIcon(getClass().getResource(filename[1])), new ImageIcon(getClass().getResource(filename[2]))};
//Here is where the pictures are stored
//That long line of code though ;D

box = new JComboBox(filename);
                new ItemListener(){
                    public void itemStateChanged(ItemEvent event){
//This is my anonymous class to handle the picture events

        picture = new JLabel(pics[0]);
//And lastly, this is where I add everything to the screen

The tutorial you really want to follow would be tutorial #68. When importing pictures, it really depends on where they will be used. I have deleted my old post, so hopefully you can see this new one. Remember, if your pictures don't show up when you add them to the Eclipse project folder of your choice, try to refresh the project folder in Eclipse.8-)

-Oh yea, and also remember this is not properly indented for Java use.
+1 Landon Luman · October 5, 2014
Thanks John and Alex, you should get credits for helping so many people in Java
+1 Alex Sweps · October 5, 2014
This seems like what you are looking for:
0 Landon Luman · October 5, 2014
I mean like, being able to put an image onto a JFrame or JPanel, if I could just have an example of an image code, please
0 Alex Sweps · October 5, 2014
Post your code that you have tried so far. And do you mean images like graphics, quares and circles etc or actual jpgs ?
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator