JTextArea preferred size

Discussion in 'Java' started by Christopher Benson-Manica, Feb 9, 2009.

  1. 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.
     
    Christopher Benson-Manica, Feb 9, 2009
    #1
    1. Advertising

  2. 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
     
    Knute Johnson, Feb 9, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kerry Shetline

    Component preferred size dilemma

    Kerry Shetline, Nov 13, 2003, in forum: Java
    Replies:
    4
    Views:
    3,342
    Babu Kalakrishnan
    Dec 5, 2003
  2. Shiperton Henethe
    Replies:
    117
    Views:
    2,164
    Andy Dingley
    Dec 22, 2004
  3. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,605
    Michael Jung
    May 25, 2008
  4. Chris F.A. Johnson

    Re: Preferred way to size fonts

    Chris F.A. Johnson, Nov 5, 2008, in forum: HTML
    Replies:
    19
    Views:
    762
    Sherm Pendley
    Nov 8, 2008
  5. dorayme

    Re: Preferred way to size fonts

    dorayme, Nov 5, 2008, in forum: HTML
    Replies:
    0
    Views:
    430
    dorayme
    Nov 5, 2008
Loading...

Share This Page