Reputation: 1
I am a begginer in the java world.
I have a list with items and I need to show the image of the corresponding item in a JPanel.
For example, my JList:
cat
dog
bird
in my JList if I click on the item cat
, the JPanel should show the cat's image.
Upvotes: 0
Views: 1041
Reputation: 6054
There are many ways to do this, and you have not been specific, so I will introduce the most common ways for a beginner to do it with swing. You want to click an animal, and pop an image up in your panel.
If you want to do this with buttons, the tutorial is here:
http://download.oracle.com/javase/tutorial/uiswing/components/button.html
If you want to do this with a JComboBox (drop down menu), the tutorial is here (and they even have an exact example of what you are talking about--displaying an animal picture!)
http://download.oracle.com/javase/tutorial/uiswing/components/combobox.html
I assume you know how JPanels work, but you may not know how to actually display images in them easily. For beginners, the ImageIcon provides an easy way to put an image on the screen straight from file.
http://download.oracle.com/javase/tutorial/uiswing/components/icon.html
Sorry for just giving you a bunch of links, but your question is truly general and if you don't even know where to start with Swing, you'll need to learn a lot before you'll actually be displaying animals on a screen. But Java's Swing tutorials are far better than what I could detail in an answer, and they have code examples that you can look at too.
Upvotes: 1