Does anyone know a way to provide a background image to a JTextArea that has line wrap turned on?
The code: Image image = Toolkit.getDefaultToolkit().getImage("images/homer02.jpg"); ImagePanel quotesPanel = new ImagePanel(image); JTextArea quotesTextArea = new JTextArea(getNextQuote()); quotesTextArea.setLineWrap(true); quotesTextArea.set WrapStyleWord(true); quotesTextArea.setOpaque(false); quotesPanel.add(quotesText Area); quotesScrollPane = new JScrollPane(quotesTextArea); quotesScrollPane.setVerticalScrollBarPolicy(JScrol lPane.VERTICAL_SCROLLBAR_NEVER); quotesScrollPane.setHorizontalScrollBarPolicy(J ScrollPane.HORIZONTAL_SCROLLBAR_NEVER); quotesScrollPane.setPreferredSize(new Dimension(250, 250)); quotesScrollPane.setBorder(BorderFactory.createEmptyBorder());
With the code the way it is, the ViewPort of the JScrollPane renders the JTextArea opaque, obliterating the image. If I just put the JTextArea onto the image panel without the JScrollPane, the text won't wrap since in Swing, that functionality has moved from the AWT TextArea setting it's own wrap to the JScrollPane being responsible for it while the JTextArea merely implements Scrollable.
Image panel is just a simple extension of JPanel, and this whole thing is housed in a JWindow (no title bar) that shows quotes from the ancient Greeks in front of an image of a bust of the poet Homer. (not Mr. Simpson)
Thanks John! That plus calling setOpaque(false) on the JScrollPane itself, did the trick! It took three calls, on the JTextArea, on the JScrollPane and on the JSrollPane's viewport.