Rename an element in a JList

4

Greetings, friends.

I have a problem with Java.

I'mtryingtoaddanelementoftype"Occurrence" in a JList. This element has 4 elements inside it, which I need to keep. So far so good.

However, the problem appears when I add that element to the list

The list shows this name in the element. Because? I would like the name of the instance to appear instead of this name.

Here is the instance code:

 @Override
        public void actionPerformed(ActionEvent e) {
            //dispose();
            Ocorrencia ocorrencia = new Ocorrencia();
            ocorrencia.setLocationRelativeTo(null);
            ocorrencia.setVisible(true);
            ocorrenciasAtivas.modeloOcorrencias.addElement(ocorrencia);

        }
    
asked by anonymous 23.11.2015 / 17:19

1 answer

3

You need to implement toString() in your Ocorrencia class.

This method should return a readable version of your object's data as String . Since you did not do this, JList used the default implementation, which is this String ugly you're seeing.

    
23.11.2015 / 17:23