Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes JList Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList Problem" Watch "JList Problem" New topic
Author

JList Problem

ali honarmand
Ranch Hand

Joined: Oct 12, 2009
Posts: 32

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...


A. Honarmand
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2203
    
    7
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

Joined: Jul 26, 2007
Posts: 10451
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
ali honarmand
Ranch Hand

Joined: Oct 12, 2009
Posts: 32

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JList Problem