Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: JTextArea in GridBagLayout
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JTextArea in GridBagLayout



Hi Dave Taubler,

Not sure offhand why the LineWrap settings would cause
a problem. But have you tried using
GridBagConstraints.fill = both, to allow the JTextArea
to remain fully visible in its display area?

I added the fill = both, but the component is still not appearing in a reasonable size. In one case, it seemed to pick up the width of the button in the cell below.

Second, when are you setting the text that will appear
in the JTextArea? You said that you want the
JTextArea's size to be calculated by the amount of
text present. Once a JTextArea's size is set, it's
set. I haven't yet found a reliable way to
dynamically resize a JtextArea, and I've looked for
one! So if you are passing the text to the JTextArea
in the constructor, then the size of the JTextArea
might get set properly. I you are attempting to pass
text to the JTextArea *after* it's been constructed,
however, then don't expect its size to change
accordingly.

I passed the text to the constructor.

I think what I need is a way to set the width to a specified number of pixels, but allow the height to be whatever is needed. Is there a way to do this? I want to ensure that all the text would be visible regardless of the platform, font, etc that might be used.

Thanks

-- original message --

I created a JTextArea in a GridBagLayout without using a JScrollPane
(because I never want scrolling). The JTextArea displayed fine, but then I
added the lines:

theItem.setLineWrap(true);
theItem.setWrapStyleWord(true);

After that, the JTextArea would not display, as if its size somehow became
zero. I was not setting the Minimum, Preferred, or Maximum sizes because I
wanted them to be calculated based on how much text was present. Why does
turning on wordwrap make this no longer work? How such I ensure that the
component has a reasonable size? I really would rather not have to specify a
pixel size for the JTextArea.

Thanks


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.