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

  • Home
  • SEARCH
  • 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 8854915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:59:45+00:00 2026-06-14T13:59:45+00:00

The word wrapping method provided for JTextArea is not working in my program. Why

  • 0

The word wrapping method provided for JTextArea is not working in my program. Why isn’t it working? How can I fix it? Here is the code:

    text= new JTextArea(15,65);

    text.setWrapStyleWord(true); // word wrapping enabled

    text.setPreferredSize(new Dimension(getPreferredSize()));

Here is the screenshot. The last word goes out of frame.
enter image description here

  • 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-14T13:59:46+00:00Added an answer on June 14, 2026 at 1:59 pm

    The following SSCCE let you experiment with both settings. Here you can see that using setWrapStyleWord has no effect if you do not call setLineWrap first. This is also documented in the javadoc of setWrapStyleWord.

    The best results for a readable form is setting them both to true.

    enter image description here

    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.WindowConstants;
    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    
    public class TextAreaDemo {
    
      public static void main( String[] args ) {
        EventQueue.invokeLater( new Runnable() {
          @Override
          public void run() {
            JFrame testFrame = new JFrame( "TestFrame" );
    
            final JTextArea textArea = new JTextArea( 15, 65 );
            testFrame.add( new JScrollPane( textArea ) );
    
            final JCheckBox wordWrap = new JCheckBox( "word wrap" );
            wordWrap.setSelected( textArea.getWrapStyleWord() );
            wordWrap.addItemListener( new ItemListener() {
              @Override
              public void itemStateChanged( ItemEvent e ) {
                textArea.setWrapStyleWord( wordWrap.isSelected() );
              }
            } );
            testFrame.add( wordWrap, BorderLayout.NORTH );
            final JCheckBox lineWrap = new JCheckBox( "line wrap" );
            lineWrap.setSelected( textArea.getLineWrap() );
            lineWrap.addItemListener( new ItemListener() {
              @Override
              public void itemStateChanged( ItemEvent e ) {
                textArea.setLineWrap( lineWrap.isSelected() );
              }
            } );
            testFrame.add( lineWrap, BorderLayout.SOUTH );
    
            testFrame.pack();
            testFrame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
            testFrame.setVisible( true );
          }
        } );
    
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tag with the text Click Here in it, the word wrapping
I'm wondering if word wrapping should be applied in text emails? And what about
How can I enable word wrapping in PhpStorm? I need to enable it only
I need good word-wrapping handling for Java. Not too difficult, except for one wrinkle:
If my program is printing to the console, I perform word-wrapping in a certain
I am facing a problem in word-wrapping the text in using the suggested word-wrap:break-word
I have come to the conclusion HTML enabled JTextPanes do not support word wrapping.
How can I can specific word wrapping for specific tags. For example, in LaTex
I need to write a little ruby function that does word wrapping. I have
for word in wordStr: word = word.strip() print word When the above code analyzes

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.