tags:

views:

162

answers:

2

I'm just looking for a little guidance as to how i might implement a chat box.

There needs to be a text area for user entry, and a scrolling list of past messages. Is there an easy/standard way of going about doing this?

Thanks

+1  A: 

Well, I think you made it all.

You use a JTextArea to let users enter text, then a JList for previous message, with a ListModel you update from messages polled on server.

Riduidel
will text entered into the JList wrap around, or is string length restricted to the width of the box
Allen
+2  A: 

I'm not sure about the suggestion for using a JList for previous messages .. that doesn't seem like the behavior I'd be looking for in a chat client.

I would recommend taking a look at the JTextPane class, which is intended for more "document" type data such as a running chat conversation. It is very easy to append data on the fly to the document and you can even apply styling to portions of the document (say for instance you want to show the user names of the various chat participants in bold and in different colors).

Here are a couple of links to examples:

How to Use Editor Panes and Text Panes

More TextPane specific examples

The other thing you'll probably want to think about is threading, for instance you would likely want to have a background thread that is polling for new messages so that the UI doesn't hang while you're looking for new messages to display.

BryanD