Gui problem

Okay, I’m trying to make a mission editor.

And I can’t get this extremely easy task to work. I don’t understand why.

A Mission, has tasks, tasks have dialogs.

Now I open the new tasks window and want to add a Dialog. Which I do by pressing a button.
The Frame opens and I choose whos speaking and the type in the dialog.

I then click finish.

This fires this method:

    @Action
    public void addDialog() {
        newAufgabe na = new newAufgabe();
        na.addDialog(txtText.getText(),cbWho.getSelectedItem()+"");
        this.setVisible(false);
    }

And then back in the tasks frame this method is fired.

  public void addDialog(String Text, String Who) {

        dialogs.add(new Dialog(Who,Text));

        listdata = new String[dialogs.size()];

        for (int i=0; i<listdata.length; i++){
            listdata[i] = dialogs.get(i).getWho();
        }

        lblTest.setText(listdata[0]); // this also doesn't do anything. Eventough it should change the Label. The Label doesn't change
        listDialog.setListData(listdata);
     }

Now normally the jlist should be updated. But it seems like java completely ignores the fact that this method exists.
I debugged it and it went though the whole process, it seems to be working just fine. It adds the dialog to the arraylist. it goes into the for-loop. and does what it does.

But the frame does not update not single bit. I hate guis. Or maybe this is just some netbeans related stuff. I’m always having weird simple problems with java in guis.

Tried invalidating the component or forcing repaint?

Kev

The problem is that the Dialog Object is not added to the arraylist.

It’s hard to tell from your code but are you using JList to display your info? If so the you need to learn how to use a javax.swing.ListModel. By creating your own list model you can notify listeners about changes to the data. Anytime a listmodel is used the JList signs up as a listener for it. Then when you notify listeners the JList will update its appearance.

Any kind of component that supports changing data should always be built with an appropriate model.

JList - ListModel
JTabel - TableModel
JTree - TreeModel

Sorry I forgot to say that I fixed the problem.

It seems that you need to give the JFrame you open, the JFrame Object that is opening the JFrame, so it doesn’t create another jFrame.