Hey all!

I've been struggling with a problem for a week now, and it seems that I'm stuck.

I'm trying to make a "Dynamic" Combobox? Well, I'm trying to read in an XML file, and based on the number of Nodes in that file, i wish to create a identical number of Comboboxes! (If the xml file has ten nodes, ten comboboxes must be created, if only five nodes, five comboboxes must be created). I'm really lost at this point to how its done. Need help please.

I've created the structure to read in the XML file, and I've tested it and it works.

I've decided to use comboboxes for this job, but any suggestions are taking in :-). The thing is, I have to read the content of a XML files first nodes into a combobox, and based on what is selected read in the childnodes from the selection into a second combobox, and so forth... My problem here is I don't know how to do this, because I've tried to use an ItemEvent handler, but having trouble cause, I can only have one handler, and if all comboboxes implements this handler, I goes wacky!! And How to create Eventhandler on the fly because that what I've got to do with the comboboxes in problem one??

Please I need help, so thanks in advance

Hey all

I got the answer on another forum, but here's the code: (posted on http://forum.java.sun.com
by the user, Balaji_ACK )

JFrame frame = new JFrame();
frame.setSize(500, 500);
JPanel panel = (JPanel) frame.getContentPane();
panel.setLayout(new FlowLayout());
for(int i = 0; i < rootNodesCount;i++){
JComboBox combo = new JComboBox();
DefaultComboBoxModel model = new DefaultComboBoxModel();
for(int j = 0; j < childs.length;j++){
combo.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
// handling code ..
Can reference the comboboxes u create in a List to know the references and in sequence, in case if you wish to update the next combox on the item change event of a combobox.

And he also gave me this advise: (Balaji_ACK)


1. For the depth of a root node, create the number of combo boxes.
2. Have these comboboxes in a List or vector. so that u can find the next combo box i.e u can have the handle for the combobox which hold the children of the current.
3. Can write a common event listener which finds the xml node for the selected combo item and gathers the children of the node.
4. Add the child nodes in to the next combo box in the reference vector.

But i still feel that we are trying to replicate a combo view of a tree. Tree would be more elegant for this purpose.


This question has already been answered. Start a new discussion instead.