Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6077479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:43:32+00:00 2026-05-23T10:43:32+00:00

I have several text areas aligned vertically. I want them to expand as more

  • 0

I have several text areas aligned vertically. I want them to expand as more text is typed, but put a limit on how tall they’ll become.

I’ve tried setting the max size, but that seems to be ignored. Any ideas?

    _recipients = new JTextArea();
    _recipients.setBorder( BorderFactory.createEtchedBorder() );
    _recipients.setLineWrap( true );
    _recipients.setWrapStyleWord( true );
    _recipients.setMaximumSize( new Dimension( 111, 55 ) );

    _subject = new JTextArea();
    _subject.setBorder( BorderFactory.createEtchedBorder() );
    _subject.setLineWrap( true );
    _subject.setWrapStyleWord( true );
    _subject.setMaximumSize( new Dimension( 111, 55 ) );

    //JComponent area = LAF.Area.clear(  );
    JPanel area = new JPanel( new GridLayout( 1, 2, 6, 0 ) );
    area.setOpaque( false );
    area.add( _recipients );
    area.add( _subject );

    add( area, BorderLayout.CENTER );

I recieved advice that i should use a scroll pain, but that just created an uneditable area

        JScrollPane pain = new JScrollPane();
        pain.add( _recipients );
        area.add( pain );

        pain = new JScrollPane();
        pain.add( _subject );
        area.add( pain );

EDIT

not much more to it, but

public class TestFrame extends JFrame
{
  TestFrame()
  {
    setSize( new DimensionUIResource( 800, 668 ) );
    JPanel area = new JPanel( new FlowLayout( 0, 0, 0 ) );

    Stuff thing = new Stuff();
    area.add( thing );

    add( area );
  }

  public static void main( String args[] )
  {
    TestFrame frame = new TestFrame();
    frame.show();
  }

  private static class Stuff extends JComponent
  {
    private final JTextArea _subject;

    Stuff()
    {
        setLayout( new BorderLayout() );

        _subject = new JTextArea();
        _subject.setBorder( BorderFactory.createEtchedBorder() );
        _subject.setLineWrap( true );
        _subject.setWrapStyleWord( true );
        _subject.setSize( new Dimension( 111, 55 ) );
        _subject.setMaximumSize( new Dimension( 111, 55 ) );

        JPanel area = new JPanel( new GridLayout( 1, 2, 6, 0 ) );
        area.setOpaque( false );
        area.add( _subject );

        add( area, BorderLayout.CENTER );
      }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:43:32+00:00Added an answer on May 23, 2026 at 10:43 am

    Personally, I prefer not to limit my JTextArea’s size lest I prevent the user from adding as much information as needed. Again, I feel you’re better off wrapping the JTextArea in a JScrollPane and limiting the JScrollPane vewport’s size. This can be done explicitly or implicitly by telling the JTextArea how many rows and columns to start out with. For example:

    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    
    import javax.swing.*;
    
    public class TestPanel extends JPanel {
    
       private static final int AREA_COUNT = 4;
    
       public TestPanel() {
          setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
          setLayout(new GridLayout(0, 1, 0, 5));
          for (int i = 0; i < AREA_COUNT; i++) {
             JTextArea area = new JTextArea(5, 30);
             area.setLineWrap(true);
             area.setWrapStyleWord(true);
             JPanel wrapPanel = new JPanel(new BorderLayout());
             wrapPanel.add(new JLabel("JTextArea " + i), BorderLayout.PAGE_START);
             wrapPanel.add(new JScrollPane(area), BorderLayout.CENTER);
             add(wrapPanel);
          }
       }
    
       private static void createAndShowUI() {
          JFrame frame = new JFrame("TestPanel");
          frame.getContentPane().add(new TestPanel());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several questions regarding forms and PHP but if I should put them
I have an object with several text strings as members. I want to write
I have a form with several text boxes on it. I only want to
I have several areas where I use AJAX to submit text fields. var name
I have a PHP Script which has several text areas. What I would like
I have several text fields that are dynamically populated based on user choice from
Hi I have several text input boxes, and i have a clear button, they
I have several large text files (30m+ lines, >1GB) which are being processed in
I have several paragraphs of text that are being stripped of all of their
I have one form with several text fields and one button. When i enter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.