Need java Code translation PLZ!

Can someone please translate this line of code for me, taken from Netbeans JList autogenerated code!  I just can't make anything out of this but Netbeans understands this!  

I'd like to modify this code so I could populate this list object with values of a "NodeList" object retreived from another getter method returning "NodeList" type!  I'd appreciate it if you could also help me perform this task!

jList_DataSet.setModel(new javax.swing.AbstractListModel() {
    String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
    public int getSize() { return strings.length; }
    public Object getElementAt(int i) { return strings[ i ]; }
});

regards
snajalmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
All you need do is replace the ListModel of jList_DataSet with one of your own. Are you talking about the jdk api NodeList class?
0
for_yanCommented:
It just creates listModel for your JList which wil show strings Item1, Item2, etc
0
for_yanCommented:
Just put values of your NodelIst inside the array strings inside this code
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

CEHJCommented:
e.g.
ListModel nodes = new DefaultListModel();
for(int i = 0;i < nodeList.getLength();i++) {
	nodes.add(nodeList.item(i);
}
jList_DataSet.setModel(nodes);

Open in new window

0
for_yanCommented:

Something like that inside this model:
String[] strings = new String[nl.getLength()];
for(int j=0; j<strings.length; j++)strings[j] = nl.item().getVlaue();

Open in new window

0
snajalmAuthor Commented:
I know what it does but I don't understand this construct in specific!  It's instantiating an AbstractListModel but how can you come up with the following "{" and the items in there which I have no clue how they're put together this way and why're they there for!

new javax.swing.AbstractListModel() {
    String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
    public int getSize() { return strings.length; }
    public Object getElementAt(int i) { return strings[ i ]; }
}

And yes "CEHJ", that's the NodeList from jdk api!
0
for_yanCommented:
If you make your NodeList instance variable - II guess you can access it insioed the anonymous class
- then just assign the vluaes of your node to Strings array - something like I posted maybe with some modifications deopending on particular NodeList
- I think I used this from ww3c.dom


You can create your own class - just extend DefaultListModel - it is much more understandable than with these anonymous things
0
CEHJCommented:
>>
It's instantiating an AbstractListModel but how can you come up with the following "{" and the items in there which I have no clue how they're put together this way and why're they there for!
>>

It's just making an anonymous inner class model for the benefit of its gui builder
0
for_yanCommented:
I think this should work:

NodeList nl; //declare it as an instance variable


new javax.swing.AbstractListModel() {
//    String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
String[] strings = new String[nl.getLength()];
for(int j=0; j<strings.length; j++)strings[j]=nl.item().getNodeValue();

    public int getSize() { return strings.length; }
    public Object getElementAt(int i) { return strings[ i ]; }
}

Open in new window

0
snajalmAuthor Commented:
There is no "add" method in the ListModel or DefaultListModel classes CEHJ.
0
CEHJCommented:
Sorry that should be
DefaultListModel nodes = new DefaultListModel();
for(int i = 0;i < nodeList.getLength();i++) {
	nodes.add(nodeList.item(i);
}
jList_DataSet.setModel(nodes);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
snajalmAuthor Commented:
Thanks!
0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.