Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

AbstractListModel Customization

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
worked perfectly, thanks.
reply
    Bookmark Topic Watch Topic
  • New Topic