Anyone here good with Java Swing?

Basically, I’ve got a JList in my class that contains my main function, and I have a button that calls a JDialog. An Add button in this JDialog adds an object to a List that I’ve declared in the first class and also adds the name from the text area into a ListModel so that it will be displayed in the JList.

The problem is that for some reason, adding an object to a list from another class is making things all screwy with the list.

After I add one object, the size of the list is 1

After I add a second object, two more are added to my list

After I add a third object, three more are added to my list

So by the time I’ve added 4 names through the JDialog class, my list is now size 10. I’m really not sure how to go about fixing it. This is the code in question:

In my StartUpWindow class:

**static DrafterList listOfDrafters = new DrafterList();

static DefaultListModel listModel = new DefaultListModel();
public static class addDrafterActionListener implements ActionListener {

 public void actionPerformed(ActionEvent e) {
AddNameDialog addNameWindow = new AddNameDialog();
Component contents = addNameWindow.createComponents();


And in my class that extends JDialog:

**public static class addActionListener implements ActionListener {

 public void actionPerformed(ActionEvent e) {
String newName = nameArea.getText();     ** *// A textArea*
            *// Add a Drafter object to the DrafterList in StartUpWindow class*
**StartUpWindow.listOfDrafters.addDrafter(new Drafter(newName));**

            *// Add an element to the ListModel for the JList*


Now, I suppose I could just hack it so that my program runs through the list and listModel and takes out any blank entries, but it would be nice to not have to do that. Any help would be greatly appreciated.

It’s been a long time since I did anything with Swing, so these might be stupid questions, but:

  1. Any chance the problem is in DrafterList.addDrafter(Drafter)?

  2. Do the DrafterList and the DefaultListModel need to be static? Could that have anything to do with it?

  3. Does the ListModel have any listeners that might be doing something funny?

  4. Do you have a debugging environment? Can’t you step through the code to see where the extra list items are coming from?

I got rid of the DrafterList class because essentially all it did was manage a list object and provide the ability to shuffle the list. I added the shuffle method to my main class.

I’m just using a DefaultListModel, so everything should be managed for me. I would certainly hope that a provided Java object wouldn’t screw up my functionality.

That seems like the only real option I guess.