Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JTextArea preferred size

Reply
Thread Tools

JTextArea preferred size

 
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      02-09-2009
The Java documentation says that a JTextArea's preferred size is what
is needed to display all the text. Why, then, does a text area
created by

final JTextArea content = new JTextArea("Long string goes here.");
content.setLineWrap(true);
content.setWrapStyleWord(true);

have a preferred size of 100x30, which is absolutely not big enough
to display all the text? What I want is to tell a text area how wide
of a space I want to put it in, and for it to tell me how much
vertical space it needs to display all of its text - how do I do that?

--
C. Benson Manica | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I do not currently read any posts posted through
sdf.lonestar.org | Google groups, due to rampant unchecked spam.
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      02-09-2009
Christopher Benson-Manica wrote:
> The Java documentation says that a JTextArea's preferred size is what
> is needed to display all the text. Why, then, does a text area
> created by
>
> final JTextArea content = new JTextArea("Long string goes here.");
> content.setLineWrap(true);
> content.setWrapStyleWord(true);
>
> have a preferred size of 100x30, which is absolutely not big enough
> to display all the text? What I want is to tell a text area how wide
> of a space I want to put it in, and for it to tell me how much
> vertical space it needs to display all of its text - how do I do that?
>


JTextArea is really designed to be used inside of a JScrollPane. That
aside you need to read the documentation to see how the preferred size
is determined.

"java.awt.TextArea has two properties rows and columns that are used to
determine the preferred size. JTextArea uses these properties to
indicate the preferred size of the viewport when placed inside a
JScrollPane to match the functionality provided by java.awt.TextArea.
JTextArea has a preferred size of what is needed to display all of the
text, so that it functions properly inside of a JScrollPane. If the
value for rows or columns is equal to zero, the preferred size along
that axis is used for the viewport preferred size along the same axis."

If you want to use a JTextArea, you need to specify a number of rows and
or columns. This is to allow the size of the component to adjust for
the font being used.

So I think you need to reconsider your GUI design.

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Preferred Size, Minimum Size, Size Jason Cavett Java 5 05-25-2008 08:32 AM
What is the *preferred* way of defining text size - CCS using %... using "x-small" Shiperton Henethe HTML 117 12-22-2004 01:22 AM
JTextArea size nos Java 1 12-18-2003 02:53 PM
Component preferred size dilemma Kerry Shetline Java 4 12-05-2003 08:29 AM
JTextArea Size Kevin Munro Java 2 12-03-2003 11:15 AM



Advertisments