The Artima Developer Community
Sponsored Link

Java Answers Forum
JTextArea

2 replies on 1 page. Most recent reply: May 1, 2002 1:51 AM by Edward Brode

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Edward Brode

Posts: 2
Nickname: javaogre
Registered: Apr, 2002

JTextArea Posted: Apr 30, 2002 6:55 AM
Reply to this message Reply
Advertisement
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)

Any hope, suggestions?

Thanks,

Edward


john mattucci

Posts: 8
Nickname: mats26
Registered: Apr, 2002

Re: JTextArea Posted: Apr 30, 2002 1:26 PM
Reply to this message Reply
try this getViewport().setOpaque(false);

Edward Brode

Posts: 2
Nickname: javaogre
Registered: Apr, 2002

Re: JTextArea Posted: May 1, 2002 1:51 AM
Reply to this message Reply
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.

Thanks again,

Edward

Flat View: This topic has 2 replies on 1 page
Topic: Error in Running the class Previous Topic   Next Topic Topic: Java AWT

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use