• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JList Problem

 
ali honarmand
Ranch Hand
Posts: 32
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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...
 
Rob Camick
Ranch Hand
Posts: 2565
9
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic