Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getIcon method undefined  RSS feed

 
Peter de Boer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'am a beginner and would like to have help with the following.

If have the following code in Eclips and experience an error with getIcon. This is the code:


the Line Icon icon = getIcon ("banaan.jpg"); gives the error
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method getIcon(String) is undefined for the type CopyOfLister

at CopyOfLister.main(CopyOfLister.java:21)

help is appreciated
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter, welcome to Java Ranch!

First, please UseCodeTags (⇐Click) when posting code to make it easier to read.

The way you've written the code, getIcon() should be a static method defined in you CopyOfLister class. Is it? Assuming you need to know how to implement such a method, I'm going to add this to our Swing forum, because honestly, I can't remember. It's been too long since I worked with Swing.
 
Campbell Ritchie
Marshal
Posts: 55687
162
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Your class does not have a getIcon method. You presumably want to use that method on an instance of something else. Maybe a JLabel; I am not sure.
 
Peter de Boer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

Your class does not have a getIcon method. You presumably want to use that method on an instance of something else. Maybe a JLabel; I am not sure.


The endresult is having a window with the combobox and the icon displayed
 
Piet Souris
Rancher
Posts: 1979
67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Peter,

to get an Icon, you first have to create one. For this, have a look at the class ImageIcon,
where you see a couple of constructors that will give you an ImageIcon.

Then, after you have created the label with this icon (line 22), you could issue

if you have to.

Greetings,
Piet
 
Peter de Boer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much :-) The problems have been solved

 
Campbell Ritchie
Marshal
Posts: 55687
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done

I edited your post because you didn't have the code tags in the right place.
 
Andrea Binello
Ranch Hand
Posts: 48
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter de Boer wrote:

This is technically correct, however remember that this is a specification on the file-system that is "relative" to the current directory. This is not always a good thing and often not what you want.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!