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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:50:43+00:00 2026-05-26T02:50:43+00:00

so I Have a JTextArea for user input and then when they click a

  • 0

so I Have a JTextArea for user input and then when they click a button it writes it to a text file, I have both setLineWrap and setWrapStyleWord set to true for the JTextArea.

I would like to write to the text file the exact way it appears in the text box.

I have tried to do a replace("\n", System.getProperty("line.separator")) on the String holding the contents of the JTextArea which works, but only if the user actually hits the return key when typing the input, but if the user just keeps typing and hits the end of a line so it jumps to the line below it, the replace doesnt work.

I have also tried using a StringBuffer, I calculated how many characters would fit in on line and then ran a for loop inserting new lines at the end of each line so for the first line I would add it at position 90, 2nd line at 180, third at 270 and so on. But I soon realized that does not work in all situations because some characters are smaller than others for example you could fit more j‘s on a single line than p‘s.

What I would like to do is just figure out a way calculate the end of a line so I know where to insert the new line, but I am open to other suggestions as well. Thanks. If you think it would help to see some of my code just ask.

Update
Instead of implementing code to do this, I talked to the person who will be pretty much one of the only people using this program and he was fine with regular notepad format and I didnt realize it but as long as he has wordWrap checked in his notepad format settings then that will eliminate him having to use the side scroll in order to read the entire line, Thanks for your input

  • 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-26T02:50:43+00:00Added an answer on May 26, 2026 at 2:50 am

    Use Utilities class

    public static final int getRowStart(JTextComponent c, int offs)
    public static final int getRowEnd(JTextComponent c, int offs)
    

    you pass offset and get offset of the row start and end

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

Sidebar

Related Questions

in JOption pane I have some JTextArea where user must eneter some text. Then
A user will input text in a textarea. It is then inserted directly into
I have an app where a user can input text in a textarea. I
I have this input element: <input type="text" class="textfield" value="" id="subject" name="subject"> Then I have
The question is: How to save user input linebreak to database. (jQuery/php/mysql) I have
I have a textarea as an input in my HTML form. When any user
Possible Duplicate: Capture newline from a textarea input I have a text area where
I have a textarea field on my webpage. I am accepting the user input,
I need to have an input textbox in which I can click and the
I have a webpage that the user inputs data into a textarea and then

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.