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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:11:13+00:00 2026-06-02T20:11:13+00:00

I created a dialog box in Swing for editing data. It contains a JTextArea

  • 0

I created a dialog box in Swing for editing data. It contains a JTextArea, two JButton instances (OK & Cancel) and a JCheckBox (Wrap Text). What I wanted to do is to have the text in the text area wrapped whenever the user clicks on the check-box. I initially have the text wrapped by using setLineWrap(true).

I am using the following code:

    Runnable r1=new Runnable() {
        @Override
        public void run() {
            System.out.println("True");
            keyField.setLineWrap(true);
            keyField.requestFocus();
        }
    };

    Runnable r2=new Runnable() {
            @Override
            public void run() {
               System.out.println("FALSE");
               keyField.setLineWrap(false);
               keyField.repaint();
               keyField.requestFocus();
            }
     };
    final Thread t1=new Thread(r1) ;
    final Thread t2=new Thread(r2);

    final JCheckBox chkSwing = new JCheckBox("Word Wrap",true);

    chkSwing.addItemListener(
            new ItemListener() {
                @Override
                public void itemStateChanged(ItemEvent e) {
                    //To change body of implemented methods use File | Settings | File Templates.
                    if (e.getStateChange() == ItemEvent.SELECTED) {
                        t1.start();
                    } else if (e.getStateChange() != ItemEvent.SELECTED){
                        t2.start();
                    }
                }
            });

    panel.add(chkSwing);

The Problem

The problem is that once I deselect the check-box, the text gets unwrapped, but again checking the check-box does not wrap the text again. The console shows that the thread is being called. How to make the check-box work for setting/unsetting the word wrap behavior of the text-area?

  • 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-02T20:11:14+00:00Added an answer on June 2, 2026 at 8:11 pm

    There is no reason to start separate Threads. Even worse, you should not modify Swing components on the non-EDT. See the Concurrency in Swing tutorial

    chkSwing.addItemListener(
      new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
           keyField.setLineWrap( e.getStateChange() == ItemEvent.SELECTED );
        }
      } );
    

    will do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a user login Dialog Box in MFC, which have two edit
I am new to Robotium. I have created an alert dialog box using dialog
I've created a user login dialog box that compares the user's name and password
I have a dialog box, created with the code javascript and HTML generated below.
I want to create a input dialog box when new record is created and
I created a dialog box like this: String response = JOptionPane.showInputDialog(null,message,title,JOptionPane.PLAIN_MESSAGE); I'd like to
I have created a layout in a dialog box, and need it to be
I am using windows forms application using C#. I have created a dialog box
I have created a custom dialog box extending the DialogFragment class. As stated in
I've created a jquery dialog modal box for logging into my website: $('#login').dialog({ modal:

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.