• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextArea line wrap

 
Edward Brode
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeff Smith
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Edward Brode
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, thanks Jeff! Someone suggested the JScrollPane.getViewport().setOpaque(false), but not the JScrollPane.setOpaque(false) as well.
Thanks again,
Edward
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!