Forums Register Login

JTextArea line wrap

+Pie Number of slices to send: Send
This is deceptively simple, I am just trying to have a background
image to a JTextArea that will line wrap its text. The line wrap
seems to be only available if a JScrollPane is wrapped around
the JTextArea, but the JViewPort of the JScrollPane turns off
the transparency of the JTextArea, blocking the image.
I have tried having the JScrollPane view the panel with the
JTextArea on the panel, but the text ceases to wrap
and the JTextArea has to be scrolled which distorts the
image.
The relevant code is:

This is all part of a JWindow that shows quotes from the ancient Greeks
over an image of the poet Homer. ImagePanel is an extension of JPanel
that has an image as a background. getNextQuote() returns a quote from
a text file.
Thanks,
Edward
+Pie Number of slices to send: Send
What you need to do is call setOpaque( false ) three times, first on your text area, then on your JScrollPane, then on the JViewport that the text area is in. Then you should be able to just add the scroll pane to your image panel and I think it'll work.
Jeff
+Pie Number of slices to send: Send
Yep, thanks Jeff! Someone suggested the JScrollPane.getViewport().setOpaque(false), but not the JScrollPane.setOpaque(false) as well.
Thanks again,
Edward
The airline is called "Virgin"? Don't you want a plane to go all the way? This tiny ad will go all the way:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1344 times.
Similar Threads
Weird chars at end of line in JTextArea
Does Swing need another Layer?
Editplus/JEdit style word wrap in JTextArea
JTextArea and scrolling
Problem Updating a JButton
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:17:46.