I have a JTextArea in Java. When I place a large amount of text in it, the text area provides horizontal scrolling.
How can I make my text area wrap instead?
The first wrap() method takes the String to wrap as its first argument and the wrap length as its second argument. The second wrap() method takes for arguments. The first is the String to wrap and the second is the wrap length. The third is the newline characters to use when a line is wrapped.
Use textArea. append("text") , but I recomend JTextPane for more control like color, selection, etc.
As per @darren's answer, you simply need to wrap the string with <html> and </html> tags: myLabel. setText("<html>"+ myString +"</html>"); You do not need to hard-code any break tags.
Use the JTextArea#setLineWrap
method. This is also illustrated in the Swing JTextArea
tutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With