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

AbstractListModel Customization  RSS feed

 
Henrique Boreg
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a class Photo which contains 3 String member variables(name, title and date), and I am using another class which extends AbstractListModel to handle a JList. Inside my AbstractListModel class, I have a List object which will hold Photo objects, like this:



The thing is that my JList displays the current Photo object's reference, like Photo@f6a746 for example. Any ideas how I can still have my JList hold Photo objects but display its title attribute instead of the Photo object itself?...So the JList would actually be displaying:
Photo.getName() instead of Photo.

Thanks.
 
Ko Wey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the method
public String toString()
of your class Photo that will decide what will be shown in the list

Compile this, and run, and you will see:
 
Henrique Boreg
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
worked perfectly, thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!