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 8438955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:52:06+00:00 2026-06-10T07:52:06+00:00

So, I have JTextArea on a JPanel (BoxLayout). I also have Box filler that

  • 0

So, I have JTextArea on a JPanel (BoxLayout). I also have Box filler that fills the rest of the JPanel. I need my JTextArea to start of with single-line-height (I can manage that), and to expand and reduce when that is needed.

Word wrap is enabled, I just need it to adjust it’s height when new line is added/removed.

I tried with documentListener and getLineCount(), but it doesn’t recognize wordwrap-newlines.

I’d like to avoid messing with the fonts if it’s possible.

And, NO SCROLL PANES. It’s essential that JTextArea is displayed fully at all times.

  • 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-06-10T07:52:08+00:00Added an answer on June 10, 2026 at 7:52 am

    JTextArea has a rather particular side effect, in the right conditions, it can grow of it’s own accord. I stumbled across this by accident when I was trying to set up a simple two line text editor (restricted characters length per line, with a max of two lines)…

    Basically, given the right layout manager, this component can grow of it’s own accord – it actually makes sense, but took me by surprise…

    I'm so smallLook at me grow

    Now in addition, you may want to use a ComponentListener to monitor when the component changes size, if that’s what you’re interested…

    public class TestTextArea extends JFrame {
    
        public TestTextArea() {
    
            setLayout(new GridBagLayout());
    
            JTextArea textArea = new JTextArea();
            textArea.setColumns(10);
            textArea.setRows(1);
            textArea.setLineWrap(true);
            textArea.setWrapStyleWord(true);
    
            add(textArea);
    
            setSize(200, 200);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setVisible(true);
    
            textArea.addComponentListener(new ComponentAdapter() {
    
                @Override
                public void componentResized(ComponentEvent ce) {
    
                    System.out.println("I've changed size");
    
                }
    
            });
    
        }
    
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            new TestTextArea();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTextArea in a JPanel that I would like to use a
I have embedded a JTextArea on a JScrollPane and am using that JTextArea for
I have a JTextArea of a fixed size (300 x 33) with line wrapping
I have a JTextArea in a JPanel. How can I have the JTextArea fill
Let me start by saying that I have been reading the drag'n drop tutorial
So, I have a problem. I have a JPanel (BoxLayout, Y_AXIS). In it, I
So here's the deal: I've got a JPanel and a JTextArea inside that one.
JPanel(a).JPanel(b).JLabel JPanel(a).JTextArea I have added a KeyListener to JTextArea . When it gets invoked,
I have a class extending JPanel that I want to embed into a JFrame
I have a JComboBox named jComboBox18 and a JTextArea jTextArea11. Now I want that

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.