My new dataModel doesn't replace the old one in my JList

I'm working in a little program that allows you to place things on a map, give it a name or description. The places can have a category that you choose from a JList with a defaultListModel. If I have created some categories and choose to save my project and continue some other time, when I load the saved file everything loads perfect except my categorylist. It's still blank, and if I have a project with categories and load a new project the old categories is still there.. I can't figure out whats wrong, I've must have missed some update here?

package test;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;

import java.awt.*;
import java.util.List;
import java.awt.event.*;
import java.io.*;
import java.io.File;
import java.util.*;


public class Testar extends JFrame {


JComboBox place;

JTextField searchField;
JButton searchButton, hideButton, deletePlaceButton, whatIsHere, hideCat, newCat, delCat;
JFileChooser jfc = new JFileChooser(".");
boolean changed = false;

DefaultListModel<PlaceCategory> dataModel = new DefaultListModel<>();
JList<PlaceCategory> categoryList = new JList<PlaceCategory>(dataModel);

//  DefaultListModel<PlaceCategory> NewDataModel = new DefaultListModel<>();

Testar(){
    super("test");

    //FILEMENU  TOPP
    JMenuBar fileBar = new JMenuBar();
    setJMenuBar(fileBar);

    JMenu archive = new JMenu("File");
    fileBar.add(archive);

    JMenuItem open = new JMenuItem("Open");
    archive.add(open);
    open.addActionListener(new OpenLis());

    JMenuItem save = new JMenuItem("Save");
    archive.add(save);
    save.addActionListener(new SaveLis());

    //kategorier ÖST

    JPanel east = new JPanel();
    add(east, BorderLayout.CENTER);

    east.add(new JLabel("Categories"));

    categoryList.setVisibleRowCount(3);
    categoryList.setFixedCellWidth(50);
    east.add(new JScrollPane(categoryList));
    categoryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    //ACTIONLISTENER

    hideCat = new JButton("Hide category");
    east.add(hideCat);

    newCat = new JButton("New category");
    east.add(newCat);
    newCat.addActionListener(new NewCatLis());

    delCat = new JButton("Delete category");
    east.add(delCat);

    BoxLayout eastLayout = new BoxLayout(east, BoxLayout.Y_AXIS);
    east.setLayout(eastLayout);

    setDefaultCloseOperation(EXIT_ON_CLOSE); 
    setSize(300,300);
    setVisible(true);
    setLocationRelativeTo(null);
    setResizable(false);
}


class NewCatLis implements ActionListener{
    public void actionPerformed(ActionEvent ave){
        String categoryName;
        Color color = Color.BLACK;

        categoryName = JOptionPane.showInputDialog(Testar.this, "Name on category");
        color = JColorChooser.showDialog(Testar.this,"Chooser color", color);
        PlaceCategory pc = new PlaceCategory(categoryName, color);
        dataModel.addElement(pc);
    }
}

class OpenLis implements ActionListener{
    public void actionPerformed(ActionEvent ave){
        int answer = jfc.showSaveDialog(Testar.this);
        if(answer != JFileChooser.APPROVE_OPTION){
            return;
        }

        File file = jfc.getSelectedFile();
        String filename = file.getAbsolutePath();

        try{

            FileInputStream fis = new FileInputStream(filename);
            ObjectInputStream ois = new ObjectInputStream(fis);

            dataModel = (DefaultListModel)ois.readObject();

            System.out.println(dataModel);

//              NewDataModel = dataModel;
//              
//              dataModel.clear();
//              
//              for(int i=0; i < NewDataModel.size(); i++){
//                  PlaceCategory pc = NewDataModel.get(i); 
//                  dataModel.addElement(pc);
//                  System.out.println("addar");
//              }
//              
//              NewDataModel.clear();


            ois.close();
            fis.close();
            pack();
            validate();
            repaint();
            changed = false;

        } catch(ClassNotFoundException e){
            JOptionPane.showMessageDialog(Testar.this, "Something went wrong... "+e.getMessage());
        } catch(FileNotFoundException e){
            JOptionPane.showMessageDialog(Testar.this, "Can not open the file...");
        } catch(IOException e){
            JOptionPane.showMessageDialog(Testar.this, "Something went wrong... "+e.getMessage());
        }
    }
}

class SaveLis implements ActionListener{
    public void actionPerformed(ActionEvent ave){
        int answer = jfc.showSaveDialog(Testar.this);
        if(answer != JFileChooser.APPROVE_OPTION){
            return;
        }

        File file = jfc.getSelectedFile();
        String filename = file.getAbsolutePath();

        try{
            FileOutputStream fos = new FileOutputStream(filename);
            ObjectOutputStream oos = new ObjectOutputStream(fos);

            oos.writeObject(dataModel);

            oos.close();
            fos.close();

            changed = false;

        } catch(FileNotFoundException e){
            JOptionPane.showMessageDialog(Testar.this, "Can not open the file...");
        } catch(IOException e){
            JOptionPane.showMessageDialog(Testar.this, "Something went wrong... "+e.getMessage());
        }
    }
}

public static void main(String[] args){
    new Testar();
}
}

and my placecategory ofc!

package test;


import java.awt.*;
import java.io.*;

public class PlaceCategory implements Serializable {

private String name;
public Color color;


public PlaceCategory(String name, Color color){
    this.name = name;
    this.color = color;

}

public String toString(){
    return name;
}

public Color getColor() {

    return color;
}

public String getName(){
    return name;
}
}

Answers


Found a way to make it happen! added this after load:

categoryList.setModel(dataModel);

Need Your Help

Reduce Drag & Drop Flickering

visual-studio-2010 visual-c++ mfc drag-and-drop flicker

I've a problem with my code. I've created a class for Drag &amp; Drop but during the dragging of the object i see a annoying flickering effect for the object that i'm dragging

Binding a Rails server to port 80 on Linux without running it as root

ruby-on-rails ruby linux thin

I'm trying to find a way to bind my production Rails server to port 80 without having to run the entire server with root privileges. My question is basically the same as "Is there a way for non-root