-1

I would like to ask about how can I print the names of the chatters in a textfield that I created in my client file. Here is the code snippet of the server file that I have:

while (true) {
                out.println("SUBMITNAME");
                name = in.readLine();

                if (name == null) {
                    return;
                }
                synchronized (names) {
                    if (!names.contains(name)) {
                        names.add(name);

                        }
                        break;
                    }
                }
            }

This piece of code gets the names of the chatters but I cannot display them in a textfield. Thank you very much for your help!

4

1 回答 1

1

您可以尝试jTextArea.append("ChatterName\n")jTextArea.append("ChatterName<br/>"),(我认为中断标签可能是问题所在)。

但是JList IMO 会好得多。

 private DefaultListModel defaultListModel = new DefaultListModel() ;
 private JList jList = new JList(defaultListModel) ; 
 defaultListModel.addElement(chatterName); 

这很好地将一个喋喋不休的名字附加到一个 JList 中。

于 2012-10-18T22:13:07.400 回答