dynamically set JTextArea dimensions

Posted on 2006-04-10
Last Modified: 2008-03-04
Any pointers or examples in setting a JTextArea to the same width as a JPanel, but specifing a height?

And if the JFrame that contains the JPanel is extended (dragged bigger|smaller), resize the JTextArea to fit.
Question by:ellandrd
    1 Comment
    LVL 92

    Accepted Solution

    try something like:

    JPanel panel = new JPanel(new BorderLayout());
    JTextArea ta = new JTextArea();
    JScrollPane sp = new JScrollPane(ta);
    sp.setPreferredSize(new Dimension(Integer.MAX_VALUE, desiredHeight));
    sp.setMaximumSize(new Dimension(Integer.MAX_VALUE, desiredHeight));
    panel.add(BorderLayout.NORTH, sp);

    you can get rid of the scroll pane if you don't want one. in which case set the preferred size of the ta

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    tenRun challenge 28 67
    powerN  challenge 3 36
    network + 7 58
    JAVA part two 4 10
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now