• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JList Problem

 
Ranch Hand
Posts: 32
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I'm using JList to show some departments to the customer but right now nothing is viewed. have recently started working on Swing part of applications. I have studied tutorials at
http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html
but I have problems using List model. Like I can not call "addElement" on a ListModel Object.
I should mention that I'm using NetBeans 6.9.1 IDE.
here is the code I use:

DefaultListModel model = new DefaultListModel();
for (Iterator<Department> it = depts.iterator(); it.hasNext();) {
Department department = it.next();

model.addElement(department.getDept_name());

}
this.jLst_departments.setModel(model);

any kind of help is appreciated, codes work better...
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you posted looks fine.

Read the JList API and follow the link to the Swing tutorial on "How to Use List" for a working example that dynamically adds element to the list.

If you need more help then post your SSCCE that demonstrates the problem.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ali honarmand wrote:...
Like I can not call "addElement" on a ListModel Object.
I should mention that I'm using NetBeans 6.9.1 IDE.



Can you elaborate on why you cannot call these methods?
You mention Netbeans. Have you used theUI builder to generate your code? If yes, I would strongly recommend to scrap it immediately and hand code.
 
ali honarmand
Ranch Hand
Posts: 32
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:

ali honarmand wrote:...
Like I can not call "addElement" on a ListModel Object.
I should mention that I'm using NetBeans 6.9.1 IDE.



Can you elaborate on why you cannot call these methods?
You mention Netbeans. Have you used theUI builder to generate your code? If yes, I would strongly recommend to scrap it immediately and hand code.


As I mentioned before I'm a newbie in Netbeans and also GUI in Java. I have found it a very interesting place. The problem was that "model" property of the "JList" was set to use "List Model Editor" I changed it to "Custom Code" and everything is fine right now.
Thanks for your attention and time.
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic