-2

i don't know what;s goin on, please help me master

private void btn_sendActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try {
        server_writer.write(cmb_server.getSelectedItem() + ":" +txt_chat.getText());
        server_writer.newLine();
        server_writer.flush();
    } catch (IOException ex){
        System.out.println("Failed");
    }

    list_chat.add("Me : " + txt_chat.getText()); // ERROR
    txt_chat.setText("");
}

*Note : App chatting with Jlist(Client-Server)

2 Answers2

0

Assuming that list_chat is a JList, the error tells you that you should add a Component instead of a String when using the add() method. See the API documentation.

I think you want to add elements to the list, the way it's explained in the answer to this question: Adding elements to a JList (but that's only a guess, you're question isn't clear).

What happens when you replace the line that causes the error with:

list_chat.addElement("Me : " + txt_chat.getText());

I think that should work.

Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
0

Guessing: list_chat is some sort of UI element that has a method [add()][1] that expects some JComponent as argument.

But this here:

"Me : " + txt_chat.getText()

results in a String object. A String is not a UI component.

And that is what the compiler is telling you. So the real answer here is: learn to read those compiler messages. They tell you exactly what the problem is ...

GhostCat
  • 137,827
  • 25
  • 176
  • 248