0

I'm trying to create a chat app GUI with the message bubbles and all that. I've managed to make the bubbles with a JTextArea and a custom border.

Now, when I try to add them to a BoxLayout(Closest thing to a vertical FlowLayout I could find) the text Areas never wrap the text.

I had to set the Maximum size to equal the Preferred size to stop the layout from expanding the JTextArea. Maybe it has something to do with that?s

ggfpc
  • 86
  • 8
  • 1
    Google, `JTextArea wrap text`. Better to do this sort of search *before* asking here, since there's little benefit to the site to having duplicate quesitons. – Hovercraft Full Of Eels Oct 28 '15 at 21:47
  • 1
    Also, **never** set a JTextAreas size or preferredSize, or maximal size. Instead only set its displayed columns and rows. – Hovercraft Full Of Eels Oct 28 '15 at 21:48
  • A `JTextArea` will benefit from been contained within a `JScrollPane`, rather then been added to a container itself – MadProgrammer Oct 28 '15 at 21:51
  • You should use "textArea.setLineWrap(true);" and maybe want to check this website, it may help you to understand how to use text areas. https://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html – Earthx9 Oct 28 '15 at 21:52
  • `Closest thing to a vertical FlowLayout I could find` - you could use the [Vertical Flow Layout](http://stackoverflow.com/questions/8196530/java-vertical-flowlayout-with-horizontal-scrolling/8199584#8199584). Although I'm not sure that will fix your problem. Wrapping of the text has nothing to do with the layout manager, only the size of the text area and the properties of the text area must be set to support wrapping. – camickr Oct 28 '15 at 21:53
  • and if you add "textArea.setWrapStyleWord(true);" into your code, it will wrap word by word. – Earthx9 Oct 28 '15 at 22:03

0 Answers0