How to fill a field with "messages" for a chat?

0

I'm doing a very homemade chat. I have it connected to the BD Sql Server (for practical purposes, I know it is not viable) to save the sent messages and check them in the DBMS to verify that they are saved correctly.

The problem comes here

I can not get the message sent to stay there fixed (or up) in the upper textBox, it is replaced with the new message.

The method I use to "fill in" the upper textBox is:

How could I do that part? I work with a textBox for that, I'm new to this interface.

(Then I'll connect it with threads for the second user).

    
asked by Jose Luis 30.08.2017 в 07:41
source

2 answers

2

I advise you that if you are going to use your chat for the sending of only messages use a JTextArea the dialogs you are adding them like this:

JTextArea.append(" tu mensaje"+"\n");

The "\n" character is for you to do a line break each time you add a new message to the textArea.

If you want something more personalized like images and buttons, use a JTextPane.

    
answered by 30.08.2017 / 15:10
source
0

You have to go accumulating the string you want to write. In your case:

while(rs.next()){
    mensaje += rs.getString("MENSAJE"); //acumulamos en mensaje
    txtVentanaChatComp.setText(mensaje);
}

For the position of the text within the text window, you will have to modify the properties of the component to indicate where you want the text to be placed (up, down, left, right, center, etc.).

I hope this resolves your doubt.

    
answered by 30.08.2017 в 09:08