Skip to content
Advertisement

Make ArrayList to JScrollPane

I have an Array List of ‘n’ number of different Chats That are Wrapped with a width below is the code for a TextArea Block

JavaScript

And an Array List That looks Like

JavaScript

Already Tried

JavaScript

It didnt work got this output instead: text thats shown

Advertisement

Answer

So, imagine a Chat class that holds a String that represents the chatter (or better, a well-defined User type object) as well text that this user is sending:

JavaScript

Then you could create a list model and a JList that hold objects of this type:

JavaScript

Then you could create a renderer that displays the Chatter’s text as the default renderer text, and the chatter’s name in a titled border that goes around the individual renderer (the default renderer is a JLabel):

JavaScript

The whole thing could look like:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement