tags:

views:

17

answers:

1

Hi, this a a part of my code ,but i don't know that why it shows two chat frames for me when i click on the list? also this is a client/server application with 127.0.0.1 IP address.would you please help me?

   private InformationClass client;
   private static DefaultListModel model = new DefaultListModel();
   private ListSelectionModel moDel;

/** Creates new form ListFrame */
public ListFrame(InformationClass client) {
    initComponents();
    this.client = client;
    jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);


    fillTable();

}


 private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {                                    

    ChatFrame frame = new ChatFrame(client);
    frame.setVisible(true);

} 


 public void fillTable() {
    try {
        List<InformationClass> list = null;
        list = Manager.getClientListFromMySQL();
        if (list == null) {

            JOptionPane.showMessageDialog(this, "You should add a person to your list", "Information", JOptionPane.OK_OPTION);
            return;
        } else {


            for (int i = 0; i < list.size(); i++) {
                InformationClass list1 = list.get(i);
                model.add(i, list1.getId());
            }

            jList1.setModel(model);
        }


    } catch (SQLException ex) {
        Logger.getLogger(ListFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}
A: 

jList1ValueChanged is called twice, when selection changes. Once with evt.getValueIsAdjusting() true and once with false.

Why do you open the frame when the selection changes and not add a button to open the frame, or react to double-click on the list?

EDIT: If you really want to react to the click, just use the mouseClicked event. Changing selection by keyboard will be ignored then.

Peter Lang
I want the next frame open just when the user clicked on the one name of that list.so how can i do that if I can not use ValueChanged? thanks
Johanna
Thanks ,it works.but I have a question which is about chat. when I click on Peter ,one frame will be shown for me like now .but how about you(one frame must be shown for you suddenly)? like doing chat in yahoo!messenger.
Johanna